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, and pnorm and qnorm 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.
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 line should readshare <- pnorm(1.96) - pnorm(-1.96).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). Step 3 uses this.
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 same distance, measured from either end
The range from x̄ − 1.96 × SE to x̄ + 1.96 × 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 μ. With a sample this large, the sample's SD s stands in for it: SE ≈ s ÷ √n.
Your task: replace the NA with the standard error, s ÷ √n. The next two lines then build the 95% interval, x̄ ± 1.96 × SE.
Hint 1
sqrt(n) is the square root of n.Hint 2
The first line should readse <- s / sqrt(n).In your own words
In one or two sentences: why does x̄ ± 1.96 × SE reach μ for 95% of random samples? Use the picture and step 1.
One way to say it. 95% of samples give an x̄ within 1.96 SE of μ (step 1). For each of those samples, μ is within 1.96 SE of x̄, so the interval x̄ ± 1.96 × SE reaches it. The other 5% of samples give an x̄ farther away, and their intervals miss μ.
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. The 95% interval used z = 1.96. A 99% interval uses the same recipe, x̄ ± z × SE, with a z that leaves 99% of the normal curve in the middle.
Compared with the 95% interval, the 99% interval from the same sample is…
Your task: for 95%, qnorm(0.975) gave 1.96: 95% in the middle leaves 2.5% in each tail. For 99%, each tail holds 0.5%. Replace the NA with the z that has 99.5% of the area to its left, and Run.
Hint 1
99.5% as a proportion is 0.995.Hint 2
The line should readz99 <- qnorm(0.995).Your prediction
More confidence, wider interval. Both intervals are centred at x̄ = 4.6 minutes with SE = 0.3. Only z changes: from 1.96 to about 2.58. So the margin grows from 1.96 × 0.3 ≈ 0.59 to 2.58 × 0.3 ≈ 0.77 minutes each side: the 95% interval is [4.01, 5.19] and the 99% interval is [3.83, 5.37]. To reach μ for 99 samples in 100 instead of 95, the interval must also cover x̄'s that land further from μ, so it is wider for every sample.
Assumptions
- dataThe coffee-shop sample (n = 64, x̄ = 4.6, s = 2.4 minutes) is made up, not real data.
- simplificationThe population standard deviation σ is usually unknown, so the sample's SD s stands in for it in SE = s ÷ √n, and the normal curve gives z. With samples this large that is close; the t-distribution, which corrects for it, comes next lesson.
- distributionThe sampling distribution of x̄ is assumed close to normal (the CLT); when that holds is left for class.
- parameterz = 1.96 for 95% (qnorm(0.975) = 1.95996) and z ≈ 2.58 for 99% (qnorm(0.995) = 2.5758). The step 3 check accepts 2.58 or qnorm(0.995).
Left out: other confidence levels, choosing a level, checking the conditions on real data, and intervals for proportions.