Let’s load the Mosaic package:
require(mosaic)
In the activity, we’re told IQ scores follow a normal distribution with a mean of 100 and a standard deviation of 16. Let’s take a look at that distribution:
plotDist("norm", params=list(mean=100, sd=16), col="steelblue")
We can have R calculate this probability using the xpnorm() function in the Mosaic Package. The function has quite a few options:
xpnorm(q, mean = 0, sd = 1, plot = TRUE, verbose = TRUE,
invisible = FALSE, digits = 4, lower.tail = TRUE, log.p = FALSE,
xlim = mean + c(-4, 4) * sd, ylim = c(0, 1.4 * dnorm(mean, mean, sd)),
vlwd = 2, vcol = trellis.par.get("add.line")$col, rot = 45,
manipulate = FALSE, ...)
We won’t use too many of those options to calculate our probability:
# P(X < 72 | normal~(100, 16))
xpnorm(72, mean = 100, sd = 16)
##
## If X ~ N(100,16), then
##
## P(X <= 72) = P(Z <= -1.75) = 0.0401
## P(X > 72) = P(Z > -1.75) = 0.9599
## [1] 0.04006
We can change the last option manipulate=TRUE
to create an interactive normal distribution. If you run this code on your computer, you can see a normal curve for various scenarios:
# P(X < 72 | normal~(100, 16))
xpnorm(72, mean = 100, sd = 16, manipulate=TRUE)
Let’s solve some of the other probability questions (question #8 in Activity #11):
# P(122 < X < 137 | normal~(100, 16))
xpnorm(137, mean = 100, sd = 16, plot=FALSE, verbose=FALSE) -
xpnorm(122, mean = 100, sd = 16, plot=FALSE, verbose=FALSE)
## [1] 0.07419
# P(84 < X < 116 | normal~(100, 16))
xpnorm(116, mean = 100, sd = 16, plot=FALSE, verbose=FALSE) -
xpnorm(84, mean = 100, sd = 16, plot=FALSE, verbose=FALSE)
## [1] 0.6827
# P(68 < X < 132 | normal~(100, 16))
xpnorm(132, mean = 100, sd = 16, plot=FALSE, verbose=FALSE) -
xpnorm(68, mean = 100, sd = 16, plot=FALSE, verbose=FALSE)
## [1] 0.9545
# P(52 < X < 148 | normal~(100, 16))
xpnorm(148, mean = 100, sd = 16, plot=FALSE, verbose=FALSE) -
xpnorm(52, mean = 100, sd = 16, plot=FALSE, verbose=FALSE)
## [1] 0.9973
To answer this question, we need to find a quantile using xqnorm:
xqnorm(p, mean = 0, sd = 1, plot = TRUE, verbose = TRUE, digits = 4,
lower.tail = TRUE, log.p = FALSE, xlim, ylim, invisible = FALSE,
vlwd = 2, vcol = trellis.par.get("add.line")$col, rot = 45, ...)
# P(X < 72 | normal~(100, 16))
xqnorm(.90, mean = 100, sd = 16)
## P(X <= 120.504825048714) = 0.9
## P(X > 120.504825048714) = 0.1
## [1] 120.5