UMD · Stats review · Terps edition

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.

Step 1 · The setup

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.

    Right-skewed: most students eat a moderate amount, a few eat a lot. The orange bar far right is the cookie smuggler. σ = 26.11 is the spread of THIS histogram: how much one student differs from the next.
    Seed
    Sample size n
    Confidence
    Step 2 · Watch the pile get built

    Watch the pile get built

    Uses the settings in the bar above (). The x-axis here zooms to fit the chosen n.

    Press play.
    Step 3 · Compare the three ways

    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.

    true mean μ our one x̄ (rep #1) Thick bar under each curve = its 95% interval

    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.

    Step 4 · How the three ways connect to the CLT

    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.

    The Central Limit Theorem (CLT): take many random samples of size n and pile up their x̄’s. If n is big enough, the pile is approximately Normal, centered at μ, with spread σ/√n, whatever shape the population has (even our skewed cookie counts with a 300-cookie smuggler).

    Way 1 · repeat sampling

    IS the pile
    It actually builds the pile from many real samples. The CLT predicts this pile; Way 1 looks at it, so it can check the prediction.

    Way 2 · bootstrap

    copies spread & shape
    Copies the pile’s spread and shape, but centered on our x̄, not μ. It resamples our one sample, whose mean is x̄, so every resample averages back to x̄. Our sample’s spread (s) is a fair stand-in for σ, so the width comes out right. No CLT assumed, but its pile is made of averages too, so it still ends up bell-shaped.

    Way 3 · CLT math

    IS the CLT, as a shortcut
    It skips building any pile and writes down the CLT’s answer: Normal(x̄, s/√n). Our x̄ stands in for μ and our s stands in for σ.
    Way 1: the real pile← predicted by (if conditions hold) →the CLT → used as a formula by →Way 3 (and Way 2 copies Way 1 by simulation, no formula needed)

    When 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).

    Step 5 · When do the CLT conditions matter?

    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 pileThe CLT’s forecast (what Way 3 uses)
    n too small (n = 3)still real, just lopsidedwrong: 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 placewrong: 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:

    ConditionWay 1 · repeat samplingWay 2 · bootstrapWay 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”

    x̄
    center
    no CLT needed
    ±
    1.96
    “95% of a Normal curve”
    needs the CLT
    ×
    s/√n
    width (SE)
    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?

    Step 6 · Does the CI catch the true mean?

    Swap in another sample, one at a time (CLT way, x̄ ± 1.96·s/√n)

    Step 7 · Build a CI with the CLT formula

    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.

    Confidence for this stepFollows the Confidence buttons in the bar at the top of the page; pick here to try other levels.

    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 isdifferentx̄ ~ N(mean = μ, SE = σ/√n)p̂ ~ N(mean = p, SE = √(p(1 − p)/n))
    Center of the CIdifferentx̄p̂ = successes / n
    SE you computedifferents / √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 ruledifferentn > 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)
    IndependencesameRandom sample; if sampling without replacement, n < 10% of the population.
    ZsameSet by the confidence level only (part 2). Same number for means and proportions.
    estimate
    x̄ or p̂
    ±
    1.96
    Z: how many SEs
    to step out each side
    ×
    SE
    s/√n or √(p̂(1−p̂)/n)

    Example · mean

    one interview, n = 100

    Example · proportion

    same 100 students

    Small 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

    fastest
    Good enough for the levels you see on every exam.

    B · Z table

    on paper
    Find 1 − α/2 inside the table, then read Z off the row and column labels.
    Watch it below ↓

    C · R

    any level, exact
    qnorm() 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.

    ArgumentWhat it means here
    ythe column to study, no quotes
    datayour one sample (data frame)
    statistic"proportion", "mean" or "median"
    type"ci" interval · "ht" hypothesis test
    method"theoretical" = the CLT formula, estimate ± Z × SE
    successwhich answer counts as a “yes” (proportions only)
    conf_levelconfidence level as a decimal; defaults to 0.95

    3Finding Z in the table, step by step

    area 0 z
    Table entry for z = shaded area to the left of z

    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.

    1. 1Tails: α = 1 − C = , so each tail is α/2 =
    2. 2Area to the left of +Z: 1 − α/2 =
    3. 3Scan the body of the table for
    4. 4Read the labels: row + column = ?
    Press ▶ to watch the lookup for the confidence level picked at the top of this step.

    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)

    1.96

    qnorm(p)

    area to the left in → x value out (reverse of pnorm)

    0.975

    rnorm(n)

    how many in → n random values out

    30
    FunctionYou give itIt gives backQuestion it answers
    dnorm(x)a valuecurve heightHow tall is the curve here? (used to draw it)
    pnorm(x)a valueprobabilityWhat share falls below x?
    qnorm(p)a probabilitya valueWhich x has p of the area below it? → Z for a CI
    rnorm(n)how manyrandom valuesGive 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).