Area, Not Height: the normal curve in R
Where probability lives on a continuous curve, how pnorm and qnorm find it, and binomial probabilities in R.
Assumes the binomial distribution and a little R (running code, assigning with <-). New here: density, z-scores, pnorm, qnorm.
The curve appears here once you lock in your prediction.
1. Can a probability curve rise above 1?
A machine fills 1-kg bags of rice. Bag weights follow a normal curve: mean 1 kg, SD 0.2 kg.
For a binomial, the height of each bar is a probability.
Could the height of this curve, at its peak, be greater than 1?
You predicted no. That's the natural reading after last week, when a bar's height was its probability. Look at the chart: the peak is about 2 per kg, above the dashed line at 1. Yet the total area is still 1.
On a continuous curve the height is a density: probability per kg. Probability comes from area, height × width. A narrow strip 0.01 kg wide under a height of 2 holds about 2 × 0.01 = 0.02.
Try it: drag the SD to 0.1. The peak rises to about 4 per kg. A probability of 4 is impossible, so the height can't be one.
You predicted yes, and the chart agrees: the peak is about 2 per kg, above the dashed line at 1, while the total area stays 1.
The height is a density: probability per kg. Probability is area, height × width. A strip 0.01 kg wide under a height of 2 holds about 2 × 0.01 = 0.02.
Try it: drag the SD to 0.1. The curve gets narrower and taller (peak about 4 per kg) because the same area of 1 must fit in less width.
You predicted it would take a drawing error. The chart is drawn from the normal formula, and its peak is about 2 per kg, above the dashed line at 1. Its total area is exactly 1, as it must be.
The height is a density: probability per kg. Probability is area, height × width. A strip 0.01 kg wide under a height of 2 holds about 2 × 0.01 = 0.02.
Try it: drag the SD to 0.1. The peak rises to about 4 per kg with nothing drawn wrong: the same area of 1 squeezed into less width.
With the SD at 0.2 kg, the curve's height between 0.99 and 1.01 kg is about 2 per kg. What share of bags weigh between 0.99 and 1.01 kg?
2. What share of nights are shorter than 6 hours?
Students' nightly sleep follows a normal curve: mean 7.1 hours, SD 0.9 hours.
pnorm(x, mean, sd) returns the area to the left of x: the share below x. A z-score, (x − mean) / SD, says how many SDs x is from the mean; pnorm(z) gives the same area on the standard normal curve (mean 0, SD 1).
Find the z-score of 6 hours as z_short and the share of nights under 6 hours as p_short. Then move the slider to 6 to check them.
Hint 1
A z-score counts SDs from the mean: subtract the mean, then divide by the SD.mu and sigma are already set.Hint 2
z_short <- (6 - mu) / sigma. For p_short, copy the worked example's line with 6 in place of 8; pnorm(z_short) should print the same number.3. How do you go back from a share to hours?
Sleep: mean 7.1 hours, SD 0.9 hours (mu and sigma).
A night at the 90th percentile is longer than 90% of nights. qnorm(share, mean, sd) runs pnorm backwards: it takes a share and returns the value with that share to its left. Without mean and sd, qnorm(share) returns the z-score.
A night at the 30th percentile: is its z-score positive or negative?
Find the z-score of the 90th percentile as z90, the hours at the 90th percentile as h90, and the share of nights between 6 and 8 hours as p_6_8.
Hint 1
Shares go in as proportions: the 90th percentile is 0.9. Check your answers on the slider.Hint 2
z90 is qnorm(0.9). h90 is the worked example's line with 0.9 in place of 0.25. p_6_8 is pnorm(8, …) minus pnorm(6, …), each with mean = mu, sd = sigma.In your own words
What goes into pnorm, and what comes out? And qnorm? One or two sentences.
One way to say it: pnorm takes a value (or a z-score) and returns the area to its left, a share between 0 and 1. qnorm does the reverse: it takes a share and returns the value with that share to its left. qnorm(pnorm(6, 7.1, 0.9), 7.1, 0.9) gives back 6.
Compare: did yours say which side the area is on (to the left)? A share of nights longer than 9 hours needs 1 - pnorm(9, mu, sigma).
Number who accept, of 16 (binomial, p = 0.7)
Each bar's height is the probability of exactly that many accepting.
4. How many of 16 admits will say yes?
Suppose Minerva's yield is 70%: 70% of admitted students accept their offer. You meet a random 16 recently admitted students; each accepts with probability 0.7, independently.
The number who accept is binomial: n = 16, p = 0.7. Its mean is n × p; its SD is √(n × p × (1 − p)) = 1.83. dbinom(k, size, prob) is the height of bar k; pbinom(k, size, prob) adds the bars from 0 up to k, including k.
Compute expected (how many of the 16 you expect to accept), p_14_16 (14, 15 or 16 accept) and p_under13 (fewer than 13 accept).
Hint 1
A binomial's mean is trials × chance. For 14 to 16, add three bars:dbinom accepts 14:16 as k.Hint 2
expected <- n * p and p_14_16 <- sum(dbinom(14:16, size = n, prob = p)). For p_under13: which is the largest count that is fewer than 13? Give that k to pbinom(k, size = n, prob = p).5. Check yourself
Commute times in a city follow a normal curve with mean 30 minutes and SD 8 minutes. Which R line gives the share of commutes between 20 and 40 minutes?
pnorm(40, 30, 8) - pnorm(20, 30, 8)dnorm(40, 30, 8) - dnorm(20, 30, 8)pnorm(40, 30, 8)Same city. The slowest 10% of commutes take longer than how many minutes? Which R line answers it?
qnorm(0.9, 30, 8)qnorm(0.1, 30, 8)pnorm(0.9, 30, 8)Your predictions
You should now be able to:
- explain why a density curve can rise above 1 while every probability, an area, stays between 0 and 1 (if not, revisit step 1);
- use
pnormfor a share below or between values, andqnormfor a percentile, in hours or as a z-score (steps 2 and 3); - compute binomial probabilities with
dbinomandpbinom, including “fewer than” (step 4).
Back again: three quick questions
Newborn weights follow a normal curve with mean 3.4 kg and SD 0.5 kg. Which R line gives the share of newborns heavier than 4 kg?
1 - pnorm(4, 3.4, 0.5)pnorm(4, 3.4, 0.5)dnorm(4, 3.4, 0.5)What does pnorm(0) return?
A normal curve's height at its peak is 1.6. What does that tell you?
Assumptions
- dataRice bags (mean 1 kg, SD 0.2 kg) and nightly sleep (mean 7.1 h, SD 0.9 h) are invented normal curves. The yield of 70% and the 16 admits are from the lesson's pre-class problem.
- distributionEach admitted student accepts independently with probability 0.7, so the number who accept is binomial(16, 0.7): mean 11.2, SD √(16 × 0.7 × 0.3) = 1.83.
- simplificationCharts compute the normal curve, its areas and the binomial bars in the page; the R cells compute the same quantities with
pnorm,qnorm,dbinomandpbinom.
Left out: using a normal curve in place of binomial bars, and the uniform distribution.