Catch the Mean
Build a confidence interval for a mean from one sample, and see what changes from 95% to 99%. You'll use R.
Assumes: the sampling distribution of the sample mean, the standard error SE = σ ÷ √n, the t-distribution with df = n − 1 for when σ is unknown, and pnorm, qnorm and qt in R. Each R task is one short edit.
1. Where do sample means land?
Recall: the means x̄ of many random samples of size n pile up in a normal curve centred at the population mean μ. Its standard deviation is the standard error, SE = σ ÷ √n, where σ is the population standard deviation: the SD of the whole population, not of one sample. For this step, suppose σ is known.
What share of sample means land within 1.96 SE of μ, on either side?
The middle area, as one subtraction
Each curve is the standard normal curve. Its axis is the distance of x̄ from μ, counted in SEs, so 0 is μ itself. pnorm(z) gives the shaded area to the left of z. Take the orange tail (middle picture) away from everything left of 1.96 (first picture), and only the blue middle is left.
Your task: on the standard normal curve, the share between −1.96 and 1.96 is the area left of 1.96 minus the area left of −1.96. Replace the NA with the area left of −1.96, and Run.
Hint 1
pnorm(z) is the area to the left of z.Hint 2
The NA becomespnorm() of the left edge of the shaded area, a negative number.Your prediction
You predicted about 95%, and the cell should give 0.95: 95% of sample means land within 1.96 SE of μ. The other 5% split evenly, 2.5% too high and 2.5% too low. One step further: if the SE is 5 kg, 95% of sample means land within 1.96 × 5 = 9.8 kg of μ.
You predicted about 68%. That's the share within 1 SE of μ. Within 1.96 SE, about twice as far, the cell should give 0.95. One step further: if the SE is 5 kg, 95% of sample means land within 1.96 × 5 = 9.8 kg of μ.
You predicted about 99.7%. That's the share within 3 SE of μ. Within 1.96 SE the cell should give 0.95: 5% of sample means land farther out. One step further: if the SE is 5 kg, 95% of sample means land within 1.96 × 5 = 9.8 kg of μ.
You predicted about 50%. Half the sample means land within only about 0.67 SE of μ. Within 1.96 SE, the shaded area in the plot, the cell should give 0.95. One step further: if the SE is 5 kg, 95% of sample means land within 1.96 × 5 = 9.8 kg of μ.
The other way round: qnorm(0.975) gives back 1.96, the z with 97.5% of the area to its left (the middle 95% plus the 2.5% left tail). When σ is unknown, from step 2 on, R's qt() does the same job on the t-distribution.
The same distance, measured from either end
The range from x̄ − t × SE to x̄ + t × SE is the 95% confidence interval for μ. It relies on the CLT making the distribution of x̄ close to normal.
2. How long is the wait, on average?
A coffee shop wants μ, the mean wait over all its orders. It times a random sample of n = 64 orders: mean wait x̄ = 4.6 minutes, SD s = 2.4 minutes. The population standard deviation σ (the SD of all its orders' waits) is unknown, like μ. As in the last lesson, that forces two changes, whatever n is:
- Estimate σ with the sample SD s, dividing by n − 1 (R's
sd()does this): SE = s ÷ √n. - Replace 1.96 with t from the t-distribution with df = n − 1 = 63:
qt(0.975, df = 63)≈ 1.998.
The 95% interval is x̄ ± t × SE.
Your task: with n = 64 and s = 2.4 minutes, replace the NA with the standard error, s ÷ √n. The t95 line is done for you: qt(0.975, df = n - 1), about 1.998. The last two lines then build the 95% interval, x̄ ± t × SE, around x̄ = 4.6.
Hint 1
sqrt(n) is the square root of n.Hint 2
Divides by sqrt() of the sample size, which is stored as n.In your own words
In one or two sentences: why does x̄ ± t × SE, with t ≈ 1.998, reach μ for 95% of random samples? Use the picture and step 1.
One way to say it. For 95% of samples, the t-statistic (x̄ − μ) ÷ SE lands between −1.998 and 1.998 (that is what qt(0.975, df = 63) means), so x̄ is within 1.998 SE of μ. For each of those samples, μ is within 1.998 SE of x̄, so the interval x̄ ± 1.998 × SE reaches it. The other 5% give an x̄ farther away, and their intervals miss μ. It is step 1's idea, with the t-distribution in place of the normal curve because s stands in for σ.
Compare with yours: did you use that the gap between x̄ and μ is the same measured from either end? That's what turns a fact about where x̄ lands into an interval around x̄.
3. A 99% interval: wider or narrower?
Same sample: n = 64 orders, x̄ = 4.6 minutes, s = 2.4 minutes, so SE = 2.4 ÷ √64 = 0.3 minutes. σ is still unknown, so the 95% interval used t = qt(0.975, df = 63) ≈ 1.998. A 99% interval uses the same recipe, x̄ ± t × SE, with a t that leaves 99% of the t-distribution (df = 63) in the middle.
Compared with the 95% interval, the 99% interval from the same sample is…
Your task: for 95%, qt(0.975, df = n - 1) gave 1.998: 95% in the middle leaves 2.5% in each tail. For 99%, each tail holds 0.5%. Replace the NA with the t (df = n − 1 = 63) that has 99.5% of the area to its left, and Run. The last lines build x̄ ± t99 × SE, with x̄ = 4.6 and SE = 0.3.
Hint 1
Step 2 usedqt(0.975, df = n - 1) for 95%. 99.5% as a proportion is 0.995.Hint 2
Useqt() as in step 2, with 0.995 in place of 0.975 and the same df.Step 4 draws your two intervals side by side.
Your 95% and 99% intervals for the mean wait
4. Which interval is wider, and why?
Both intervals are centred at x̄ = 4.6 minutes and use SE = 2.4 ÷ √64 = 0.3. Only the t value (df = 63) differs: about 1.998 for 95%, about 2.656 for 99%.
You predicted the 99% interval would be narrower. It sounds right: more confidence, more precision. But the chart shows the opposite: the 99% interval reaches further on both sides.
You predicted the same width, since the sample is the same. x̄ and SE are the same, but t is not: 2.656 instead of 1.998. The chart shows the 99% interval reaching further on both sides.
You predicted it depends on the sample. For any sample, both intervals share x̄ and SE, and the 99% one multiplies SE by a bigger t: 2.656 instead of 1.998 here. So it is wider every time, as the chart shows.
Some people predict the 99% interval is wider: “to be surer, allow more room.”
Look at the chart. Why is that prediction right? Think about what an interval must do to reach μ for 99 samples in 100 instead of 95.
More confidence, wider interval. To reach μ for 99% of samples, the interval must cover x̄'s that land further from μ, so it reaches further: 2.656 × 0.3 ≈ 0.80 minutes each side instead of 1.998 × 0.3 ≈ 0.60.
Try it on a new case: another sample of 64 (df = 63 again) with SE = 2 minutes. The 95% interval reaches 1.998 × 2 ≈ 4.0 minutes each side of x̄; the 99% interval reaches 2.656 × 2 ≈ 5.3 minutes.
You predicted wider, and the chart shows it: same center, but the 99% interval reaches further on both sides.
Some people expect the 99% interval to be narrower: “more confidence should mean a more precise answer.”
How would you explain to them why it's wider?
More confidence, wider interval. To reach μ for 99% of samples, the interval must cover x̄'s that land further from μ, so it reaches further: 2.656 × 0.3 ≈ 0.80 minutes each side instead of 1.998 × 0.3 ≈ 0.60.
Try it on a new case: another sample of 64 (df = 63 again) with SE = 2 minutes. The 95% interval reaches 1.998 × 2 ≈ 4.0 minutes each side of x̄; the 99% interval reaches 2.656 × 2 ≈ 5.3 minutes.
Assumptions
- dataThe coffee-shop sample (n = 64, x̄ = 4.6, s = 2.4 minutes) is made up, not real data.
- simplificationStep 1 supposes σ is known, to show where the 95% comes from. Steps 2 to 4 treat σ as unknown, as it almost always is.
- interpretationBecause σ is estimated, two things change, whatever n is: s (dividing by n − 1, as R's sd() does) replaces σ in SE = s ÷ √n, and the multiplier comes from the t-distribution with df = n − 1 = 63, not the normal curve. At df = 63 they are close (1.998 vs 1.96 for 95%), but with σ unknown t is still the one to use.
- distributionThe t interval is exact for independent draws from a normal population. Wait times are usually skewed, so here it is an approximation that relies on the CLT making x̄ close to normal; it improves as n grows. When it holds is left for class.
- parametert = qt(0.975, 63) = 1.9983 for 95% and qt(0.995, 63) = 2.6561 for 99%. With SE = 0.3: half-widths 0.600 and 0.797 minutes; intervals [4.00, 5.20] and [3.80, 5.40]. The step 3 check accepts t99 within 0.01 of qt(0.995, 63). Step 1 uses z = 1.96 (qnorm(0.975)) for the σ-known case.
Left out: other confidence levels, choosing a level, checking the conditions on real data, and intervals for proportions.