The Cookie Question
How many cookies does a Terp eat at the Y in one semester? A live demo of the three ways to build the sampling distribution of x̄, and whether the confidence interval catches the true mean.
The population (in real life, we never get to see this)
Everything below is simulated, so we know the truth and can check each method against it.
Watch the pile get built
Uses the settings in the bar above (). The x-axis here zooms to fit the chosen n.
Same population, a different "one sample"
Use the bar above: each seed is a different day of interviews; n is how many students per interview; the confidence level sets how wide the intervals are. Same x-axis for every setting, so you can see the pile shrink when n grows.
Way 1's bar is where 95% of single x̄'s land (it is built from 100 samples, so it always sits on μ). Ways 2–3 can only see ONE sample, so they center on that sample's x̄: their bar is the 95% CI you would report.
The CLT predicts Way 1’s pile (when its conditions hold). Way 3 uses that prediction as a formula. Way 2 copies Way 1 by computer.
Way 1 · repeat sampling
IS the pileWay 2 · bootstrap
copies spread & shapeWay 3 · CLT math
IS the CLT, as a shortcutWhen does the CLT kick in? Try a tiny n.
5,000 samples of size n drawn from our 10,000 students (simulated live in your browser). Bars = the real pile of x̄’s (like Way 1). Dashed curve = what the CLT predicts, Normal(μ, σ/√n).
The same conditions, but each way leans on them differently
Forecast vs. thermometer. The CLT is a forecast: “if the sample is random and independent and n is big enough, the pile of x̄’s will be Normal, centered at μ, with spread σ/√n.” The conditions are what make the forecast come true. Way 1 is the thermometer: it builds the real pile and looks at it, so it works whether or not the forecast was right. Way 3 only has the forecast.
| If this condition fails… | Way 1’s real pile | The CLT’s forecast (what Way 3 uses) |
|---|---|---|
| n too small (n = 3) | still real, just lopsided | wrong: says bell-shaped |
| not independent (n = 1,000 of 10,000) | still real, slightly narrower (SE ≈ 0.78) | slightly off: says σ/√n = 0.83 |
| not random (only cookie-counter students) | real, but centered in the wrong place | wrong: says centered at μ |
The last row is why Way 1 still needs a random sample: a biased method gives a real pile of the wrong thing. Rule: the conditions matter whenever you trust the CLT’s forecast instead of looking at the real pile. Way 3 always trusts it; Way 1 never needs to.
The CLT needs three things: a random sample, independent draws (rule of thumb: n ≤ 10% of the population), and a large enough n (more if the data are skewed, like our cookies). Which part of the answer each one protects:
| Condition | Way 1 · repeat sampling | Way 2 · bootstrap | Way 3 · CLT formula |
|---|---|---|---|
| Random sample | needed protects the center: a biased sampling method puts the whole pile in the wrong place |
needed protects the center: it can only copy what the one sample contains |
needed protects the center: x̄ must be an unbiased guess for μ |
| Independence (n ≤ 10% of population) | not needed it builds the real pile, whatever the draws are like |
needed protects the width: resampling with replacement treats draws as independent |
needed protects the width: SE = σ/√n assumes independent draws |
| Large enough n | not needed a small n just gives a lopsided pile, and that is the true shape |
somewhat protects the shape: the sample must look like the population; with n = 3 there are too few possible resamples |
needed protects the shape and the 1.96: the formula assumes the pile is already Normal |
So Way 1 shows whether the forecast came true, Way 2 needs some of the conditions, and Way 3 simply trusts that they held.
Why Way 3 needs the CLT even though we “just plug in numbers”
no CLT needed
needs the CLT
needs random + independent
The arithmetic always runs. But 1.96 only captures 95% if the pile of x̄’s really is Normal, which is what the CLT guarantees once n is large. We plugged 20,000 samples of each size from our cookie population into x̄ ± 1.96·s/√n (simulated in R):
At n = 3 the “95% CI” is really a 78% CI: same formula, but the pile is still lopsided. The CLT is the check that the 1.96 recipe delivers what it promises.
Does our case meet the conditions?
Swap in another sample, one at a time (CLT way, x̄ ± 1.96·s/√n)
The CLT recipe for any confidence interval: estimate ± Z × SE
Also called a z-interval or normal-approximation CI. The CLT says the estimate’s pile is Normal, so we step Z standard errors out from our one estimate.
1Different statistic, different mean, SE and rule of thumb
The recipe is the same. What changes is the center, the SE formula and the sample-size check. Rows in orange differ; gray rows are the same for both.
| Sample mean x̄ (numbers: cookies eaten) | Sample proportion p̂ (yes/no: ate > 50?) | |
|---|---|---|
| CLT says the pile isdifferent | x̄ ~ N(mean = μ, SE = σ/√n) | p̂ ~ N(mean = p, SE = √(p(1 − p)/n)) |
| Center of the CIdifferent | x̄ | p̂ = successes / n |
| SE you computedifferent | s / √n σ is unknown, so the sample SD s stands in. | √(p̂(1 − p̂) / n) No separate σ: the proportion itself sets the spread. p is unknown, so p̂ stands in. |
| Sample-size ruledifferent | n > 30 if the population is skewed (any n is fine if the population is already Normal) | n·p̂ ≥ 10 successes and n(1 − p̂) ≥ 10 failures (count both in the observed sample) |
| Independencesame | Random sample; if sampling without replacement, n < 10% of the population. | |
| Zsame | Set by the confidence level only (part 2). Same number for means and proportions. | |
to step out each side
Example · mean
one interview, n = 100Example · proportion
same 100 studentsSmall n with unknown σ? Means usually switch to t instead of Z (qt(0.975, df = n − 1)), which is a little wider. With n = 100 the two are almost the same.
2Three ways to get Z from a confidence level (two-sided), plus a fourth that does it all
A two-sided C% interval keeps the middle C% of the Normal curve and splits what’s left, α = 1 − C, equally into two tails. So +Z is the point with 1 − α/2 of the area to its left.
A · Memorize
fastestB · Z table
on paperC · R
any level, exactqnorm() does the table lookup for you.D · R, all in one: inference() from the statsr package
Z, SE and CI in one call
A–C only give you Z; you still compute the estimate, the SE and estimate ± Z × SE yourself. With method = "theoretical", inference() does all of it in one call: it finds p̂, computes SE = √(p̂(1 − p̂)/n), gets Z for your conf_level (the same number as qnorm in C) and prints the CI. It’s the CLT formula (Way 3), done for you.
For the mean, drop success and use the numbers directly: inference(y = cookies, data = samp, statistic = "mean", type = "ci", method = "theoretical") For means it uses t in place of Z, so the interval comes out slightly wider than x̄ ± Z × SE.
| Argument | What it means here |
|---|---|
y | the column to study, no quotes |
data | your one sample (data frame) |
statistic | "proportion", "mean" or "median" |
type | "ci" interval · "ht" hypothesis test |
method | "theoretical" = the CLT formula, estimate ± Z × SE |
success | which answer counts as a “yes” (proportions only) |
conf_level | confidence level as a decimal; defaults to 0.95 |
3Finding Z in the table, step by step
This table gives the area to the left of z (the same number as R’s pnorm(z)). Rows give z to one decimal; columns add the second decimal. Printed Z tables put this little picture at the top so you know which area they list: some books list the area between 0 and z or to the right instead, and then the lookup changes.
- 1Tails: α = 1 − C = , so each tail is α/2 =
- 2Area to the left of +Z: 1 − α/2 =
- 3Scan the body of the table for
- 4Read the labels: row + column = ?
4The four Normal functions in R: dnorm, pnorm, qnorm, rnorm
Each panel uses the standard Normal (mean 0, SD 1). Red = what you give the function; green = what it gives back. qnorm is way C from part 2.
dnorm(x)
x value in → height of the curve out (not a probability)
pnorm(x)
x value in → area to the left out (a probability)
qnorm(p)
area to the left in → x value out (reverse of pnorm)
rnorm(n)
how many in → n random values out
| Function | You give it | It gives back | Question it answers |
|---|---|---|---|
dnorm(x) | a value | curve height | How tall is the curve here? (used to draw it) |
pnorm(x) | a value | probability | What share falls below x? |
qnorm(p) | a probability | a value | Which x has p of the area below it? → Z for a CI |
rnorm(n) | how many | random values | Give me n random draws |
Set x = 1.96 and p = 0.975: pnorm(1.96) = 0.975 and qnorm(0.975) = 1.96 show the same picture from opposite directions. Add mean = and sd = to use any Normal, e.g. pnorm(50, mean = 42.2, sd = 26.1).