The Standard Normal Curve

qnorm(0.95) = 1.645 (1.645 is the 95th percentile of the standard normal distribution) ‘q’ is the generic prefix for the quantile function (percentiles) pnorm(1.645) =0.95 (the area under the standard normal curve to the left of 1.645 is 95%) ‘p’ is the generic prefix for the cumulative density function (probability distribution)

qnorm(0.05) = -1.645 (-1.645 is the 5th percentile of the standard normal distribution)

pnorm(0) =0.5 (the area under the standard normal curve to the left of zero)

#Percentiles
qnorm(0.95)
## [1] 1.644854
pnorm(1.645)
## [1] 0.9500151
qnorm(0.05)
## [1] -1.644854
pnorm((-1.645))
## [1] 0.04998491
qnorm(0.5)
## [1] 0
pnorm(0)
## [1] 0.5
#Central Areas
pnorm(1)-pnorm(-1)
## [1] 0.6826895
pnorm(2)-pnorm(-2)
## [1] 0.9544997
pnorm(3)-pnorm(-3)
## [1] 0.9973002

‘r’ is the generic prefix for random variable generator. ‘d’ is the generic prefix for the probability density function.

head(rnorm(1000),5)
## [1] -0.8230762  0.6216573  1.5953392  1.4545746  0.1359148
plot(1:1000,rnorm(1000))

plot(rnorm(1000))

Plots for some probability Distributions

Standard Normal:

a <- seq(-4, 4, length=500)
b <- dnorm(a, mean=0, sd=1)
plot(a, b, type="l", lwd=2, axes = FALSE, main = "The Standard Normal Curve")

plot(a,b, type = "l", lwd = 2, axes = FALSE, xlab = "", ylab = "")
axis(1, at = -3:3, labels = c("-3s", "-2s", "-1s", "mean", "1s", "2s", "3s"))

Uniform:

a <- seq(-4, 4, length=500)
b <- dunif(a)
plot(a, b, type="l", lwd=2)

x <- seq(0, 1, length=100)
y <- dunif(x)
plot(x, y, type="l", lwd=2)

curve(dnorm, -4.5, 4.5, lwd=2, axes = FALSE, main = "The Standard Normal Curve", xlab = "", ylab = "")
axis(1, at = -4:4, labels = c("-4s", "-3s", "-2s", "-1s", "mean", "1s", "2s", "3s", "4s"))

plot(density(rnorm(100)))

plot(density(rnorm(400)))

plot(density(rnorm(1000)))

plot(density(rnorm(5000)))

plot(density(rnorm(100000)),col="blue")

x<-seq(-4,4,length=500)
s = 1
mu = 0
y <- (1/(s * sqrt(2*pi))) * exp(-((x-mu)^2)/(2*s^2))
plot(x,y, type="l", lwd=2, col = "purple", xlim = c(-3.5,3.5))

Central Area on standard Normal using lattice:

library(lattice)

px <- seq(-4, 4, length = 10000)            # Plotting normal curve
py <- dnorm(px, 0, 1)
text=round(pnorm(1)-pnorm(-1),2)

         xyplot(py ~ px,                   # xyplot Lattice
               type = "l",
               main = paste0(paste0("Area of The Standard Normal Within I SD: ",text),"%"),
               panel = function(x,y, ...){
                   panel.xyplot(x,y, ...)
                   #panel.abline( v = c(0, -1, 1), lty = 2)  

                   xx <- c(-1, x[x>=-1 & x<=1], 1)         #Color area
                   yy <- c(0,   y[x>=-1 & x<=1], 0) 
                   panel.polygon(xx,yy, ..., col='black')
               })