Probability Distribution Functions
The Standard Normal Distribution
- dnorm(x, mean = 0, sd = 1)
- pnorm(q, mean = 0, sd = 1, lower.tail = TRUE)
- qnorm(p, mean = 0, sd = 1, lower.tail = TRUE)
This gives the density or probability of getting the value x in a normal distribution with mean = 0 and sd = 1.
(This function is not used as often because the normal distribution is a continuous distribution.)
#no pec
dnorm(0.6, mean = 0, sd = 1)
This graphic of the standard normal distribution is to help visualize the purpose behind this function. (The code to create this plot is hidden and is not necessary for this course.)
x <- seq(from = -4, to = 4, length.out = 200)
y <- dnorm(x, mean = 0, sd = 1)
specific_y <- dnorm(0.6, mean = 0, sd = 1)
plot(x, y, type = "l",
main = "Standard Normal Distribution \n N(0, 1)",
xlab = "Z",
ylab = "Density",
ylim = c(0, 0.5))
points(x = 0.6, y = specific_y, pch = 19,
col = "darkblue", cex = 1.5)
segments(x0 = c(0.6, 0.6), y0 = c(-0.05, specific_y),
x1 = c(0.6, -4.2),
y1 = c(specific_y, specific_y),
lty = "dashed", col = "darkblue", lwd = 1.25)
dnorm_plot <- recordPlot()
replayPlot(dnorm_plot)
This gives the probability of getting a value of q or less in a normal distribution with mean = 0 and sd = 1.
# no pec
pnorm(2.25, mean = 0, sd = 1, lower.tail = TRUE)
This graphic of the standard normal distribution is to help visualize the purpose behind this function. (The code to create this plot is hidden and is not necessary for this course.)
x <- seq(from = -4, to = 4, length.out = 200)
y <- dnorm(x, mean = 0, sd = 1)
plot(x, y, type = "l",
main = "Standard Normal Distribution \n N(0, 1)",
xlab = "Z",
ylab = "Density",
ylim = c(0, 0.5))
x_shade <- seq(from = -4, to = 2.25, length.out = 50)
y_shade <- dnorm(x_shade, mean = 0, sd = 1)
polygon(c(-4, x_shade, 2.25), c(0, y_shade, 0),
col = "forestgreen")
pnorm_plot <- recordPlot()
replayPlot(pnorm_plot)
If you wanted an upper-tail probability, you just need to change the lower.tail argument to be equal to FALSE.
#no pec
pnorm(1.5, mean = 0, sd = 1, lower.tail = FALSE)
This graphic of the standard normal distribution is to help visualize the purpose behind this function. (The code to create this plot is hidden and is not necessary for this course.)
x <- seq(from = -4, to = 4, length.out = 200)
y <- dnorm(x, mean = 0, sd = 1)
plot(x, y, type = "l",
main = "Standard Normal Distribution \n N(0, 1)",
xlab = "Z",
ylab = "Density",
ylim = c(0, 0.5))
x_shade <- seq(from = 1.5, to = 4, length.out = 50)
y_shade <- dnorm(x_shade, mean = 0, sd = 1)
polygon(c(1.5, x_shade, 4), c(0, y_shade, 0),
col = "forestgreen")
pnorm_upper_plot <- recordPlot()
replayPlot(pnorm_upper_plot)
This gives the critical value of the pth percentile (quantile) in a normal distribution with mean = 0 and sd = 1.
# no pec
qnorm(0.75, mean = 0, sd = 1, lower.tail = TRUE)
This graphic of the standard normal distribution is to help visualize the purpose behind this function. (The code to create this plot is hidden and is not necessary for this course.)
x <- seq(from = -4, to = 4, length.out = 200)
y <- dnorm(x, mean = 0, sd = 1)
plot(x, y, type = "l",
main = "Standard Normal Distribution \n N(0, 1)",
xlab = "Z",
ylab = "Density",
ylim = c(0, 0.5))
x_shade <- seq(from = -4, to = qnorm(0.75), length.out = 50)
y_shade <- dnorm(x_shade, mean = 0, sd = 1)
polygon(c(-4, x_shade, qnorm(0.75)), c(0, y_shade, 0),
col = "plum2")
qnorm_plot <- recordPlot()
replayPlot(qnorm_plot)
If you were using an upper-tail probability, you just need to change the lower.tail argument to be equal to FALSE.
# no pec
qnorm(0.025, mean = 0, sd = 1, lower.tail = FALSE)
x <- seq(from = -4, to = 4, length.out = 200)
y <- dnorm(x, mean = 0, sd = 1)
plot(x, y, type = "l",
main = "Standard Normal Distribution \n N(0, 1)",
xlab = "Z",
ylab = "Density",
ylim = c(0, 0.5))
x_shade <- seq(from = qnorm(0.975), to = 4, length.out = 50)
y_shade <- dnorm(x_shade, mean = 0, sd = 1)
polygon(c(qnorm(.975), x_shade, 4), c(0, y_shade, 0),
col = "plum2")
qnorm_upper_plot <- recordPlot()
replayPlot(qnorm_upper_plot)
The Normal Distribution - N(μ, σ2)
If you have a mean or standard deviation that are not standard, the functions can be used similarly. Just specify the new mean or standard deviation value in its respective place.
# no pec
pnorm(90, mean = 100, sd = 15, lower.tail = TRUE)
# no pec
qnorm(0.10, mean = 100, sd = 15, lower.tail = FALSE)