How Surprising Is 496 Grams?
A machine should fill cereal boxes with 500 g on average. A sample of 25 boxes averages 496 g. Is that evidence the machine short-fills, or just chance? One short R simulation helps you decide.
Assumes: the sampling distribution of the sample mean, the standard error SE = σ ÷ √n, and pressing Run on R code. There is one short R edit.
The facts
- The machine is set to fill boxes with 500 g on average.
- Single boxes vary: from years of records, their SD is σ = 10 g.
- A consumer group weighs a random sample of n = 25 boxes. Their average: x̄ = 496 g.
Two explanations
- Null hypothesis, H₀: μ = 500 g. The machine is fine; this sample came out low by chance.
- Alternative hypothesis, HA: μ < 500 g. The machine short-fills.
μ is the machine's true average fill, which nobody knows. HA says "less than" because the group suspected short-filling before weighing anything.
1. Is the machine short-filling?
A hypothesis test starts by assuming H₀ is true and asks: would a sample like ours be surprising then?
If the machine really averages 500 g, how often would a random sample of 25 boxes average 496 g or less?
Locked in. In step 2 you'll simulate a machine that really averages 500 g, and count how often its samples average 496 g or less.
2. What would samples look like if H₀ were true?
The facts: the machine is set to 500 g, single boxes have SD σ = 10 g, and our sample of n = 25 boxes averaged x̄ = 496 g. The code below builds the world of H₀: a machine that averages exactly the H₀ value. It takes 10,000 samples of 25 boxes, draws a histogram of their averages, and counts how many came out at 496 g or less. You don't need to follow every line.
Your task: replace NA in the mu0 line with the machine's average fill if H₀ is true. Then Run.
Hint 1
H₀ is "μ = …". Look at the facts in step 1.Hint 2
The line should readmu0 <- 500.Your count vs. your prediction
You predicted "often". Single boxes vary by about 10 g, so being 4 g short looks ordinary. But your count says only about 2% of samples from a fine machine average 496 g or less.
Some people predict "rarely" instead: "an average of 25 boxes can't drift far from 500 g, so 4 g short is a lot for an average."
Why might they be right? Use the histogram above: how far from 500 g do averages of 25 boxes usually land?
Averages vary much less than single boxes. σ = 10 g describes single boxes. Averages of 25 have SE = σ ÷ √n = 10 ÷ 5 = 2 g, and the histogram above is that narrow: about two-thirds of the averages land within 2 g of 500, and 95% within 4 g. So 496 g is 2 SEs below 500, out in the tail.
You predicted "rarely", and your count agrees: only about 2% of samples from a fine machine average 496 g or less.
Some people predict "often": "single boxes vary by about 10 g, so an average only 4 g short is nothing unusual."
How would you explain to them why 496 g is surprising anyway?
Averages vary much less than single boxes. σ = 10 g describes single boxes. Averages of 25 have SE = σ ÷ √n = 10 ÷ 5 = 2 g, and the histogram above is that narrow: about two-thirds of the averages land within 2 g of 500, and 95% within 4 g. So 496 g is 2 SEs below 500, out in the tail.
3. What does that share tell the consumer group?
The share you counted in step 2, about 0.02, estimates the p-value: the probability, if H₀ is true, of getting a sample mean at least as extreme as ours (here: 496 g or less, the direction HA points).
In one or two sentences of your own: what does p ≈ 0.02 say about the group's sample of 25 boxes?
One way to say it. If the machine really averaged 500 g (H₀ true), only about 2% of random samples of 25 boxes would average 496 g or less. A sample this low would be surprising under H₀, so it is evidence against H₀.
Compare with yours: does it start from "if H₀ were true"? A p-value is worked out assuming H₀, so it cannot be the chance that H₀ is true. That mix-up is the most common one.
One tail or two? HA: μ < 500 points one way, so only low averages count as "at least as extreme": one tail, p ≈ 0.02. If the question were "is the machine off in either direction?" (HA: μ ≠ 500), averages of 504 g or more would count too: two tails, p ≈ 0.04, about double. Choose the side from the question, before seeing the data.
4. When is a sample surprising enough?
The cut-off for "surprising" is set before the data are seen: the significance level α (alpha), usually 0.05. Then:
- p < α: reject H₀. The result is statistically significant: evidence against H₀, in the direction HA points.
- p ≥ α: fail to reject H₀. Not enough evidence for HA. This does not prove H₀.
For the group's sample, p ≈ 0.02 < 0.05: reject H₀. The data are evidence that the machine short-fills.
Check yourself
A study tests H₀: students sleep 7 hours a night on average, against HA: less than 7. A random sample of 40 students gives p = 0.30. Which conclusion is right?
How sure were you?
You should now be able to:
- state H₀ and HA for a claim about a mean (step 1);
- find a p-value by simulating the world of H₀, and say what it means, starting from "if H₀ were true" (steps 2–3);
- decide at α = 0.05: reject H₀ or fail to reject it, and why failing to reject is not proof (step 4).
If one of these isn't clear yet, go back to the step in brackets.
Assumptions
- dataThe cereal machine, its 500 g setting, σ = 10 g and the sample mean of 496 g are made up for this page.
- distributionSingle box weights are simulated as normal with SD σ = 10 g; σ is treated as known.
- parameterStep 2: 10,000 samples of 25 boxes (set.seed(21)), giving p ≈ 0.022; the normal-curve value is pnorm(−2) ≈ 0.023. α = 0.05 throughout.
- simplificationOne-sided test (HA: μ < 500), because the suspicion was short-filling. Step 3 mentions the two-sided version (HA: μ ≠ 500): both tails count, p ≈ 0.044 simulated.
Left out: the z formula and pnorm() for the p-value, t-tests with an unknown σ, tests for proportions, effect size and practical significance.