Statistics Chapter 9 of 15

Chapter 9: Confidence Intervals

Estimating parameters with a stated level of confidence

All chapters
On this page
What you will be able to do after this chapter
  • Explain the difference between a point estimate and an interval estimate, and what "95 percent confident" really means.
  • Build and interpret a confidence interval for a population proportion, checking the conditions.
  • Explain the t distribution and build a confidence interval for a population mean.
  • Describe how confidence level, sample size, and variability change the margin of error.
  • Plan the sample size needed for a target margin of error.
  • Build a bootstrap percentile interval and explain when it is useful.

Chapter 8 showed that a sample statistic lands near its parameter but not exactly on it, and told us how far off it typically is (the standard error). Now we turn that knowledge around. Given one sample, how can we say something honest about the unknown parameter? A single number such as "the mean commute is 34 minutes" hides how uncertain we are. A confidence interval reports the estimate and its uncertainty together: "we estimate the mean commute is between 31 and 37 minutes."

9.1

Point estimates and interval estimates

A point estimate is a single number used to estimate a parameter: \(\bar{x}\) for \(\mu\), \(\hat{p}\) for \(p\), \(s\) for \(\sigma\). It is almost never exactly right, and by itself it says nothing about how close it is likely to be. An interval estimate is a range of plausible values for the parameter. Nearly every interval in this course has the same shape:

\[\text{point estimate} \;\pm\; \text{margin of error}, \qquad \text{margin of error} = (\text{critical value}) \times (\text{standard error}).\]
Confidence interval and confidence level

A confidence interval (CI) for a parameter is computed from sample data by a method that, over repeated samples, produces an interval containing the true parameter a stated proportion of the time. That proportion is the confidence level, usually 90, 95, or 99 percent.

The logic of confidence

By the central limit theorem, about 95 percent of sample means fall within 1.96 standard errors of \(\mu\). Turn the statement around: if \(\bar{x}\) is within 1.96 standard errors of \(\mu\), then \(\mu\) is within 1.96 standard errors of \(\bar{x}\). So the interval \(\bar{x} \pm 1.96\,\text{SE}\) contains \(\mu\) for exactly those samples whose mean landed in the central 95 percent, which is 95 percent of samples.

The 95 percent describes the method, not any single interval. The parameter is a fixed number; it is the interval that changes from sample to sample. The tool below makes this concrete by drawing 100 samples and building an interval from each.

Interpreting a confidence interval

Correct: "We are 95 percent confident that the true mean lies between 7.12 and 7.94." Or, more carefully: "if we repeated this procedure with many random samples, about 95 percent of the intervals produced would contain the true mean."

Incorrect:

  • "There is a 95 percent probability that \(\mu\) is between 7.12 and 7.94." (After the data are in, the interval is fixed and \(\mu\) is fixed: either it is inside or it is not. The 95 percent describes the procedure.)
  • "95 percent of the data lie between 7.12 and 7.94." (An interval for the mean says nothing about where individual observations fall. It is far narrower than the spread of the data.)
  • "95 percent of sample means will fall in this interval." (Not so: the next sample gives a different interval.)
  • "A 95 percent interval from one study makes a second study 95 percent likely to give a value inside it." (No: the capture rate for a new sample mean is lower.)
9.2

Confidence interval for a proportion

From Chapter 8, \(\hat{p}\) is approximately \(N\!\left(p,\ \sqrt{p(1-p)/n}\right)\). We do not know \(p\), so we estimate the standard error by substituting \(\hat{p}\):

\[\text{SE}(\hat{p}) = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}, \qquad \text{CI: } \hat{p} \pm z^* \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}.\]

Here \(z^*\) is the critical value: the number of standard errors needed to capture the central \(C\) percent of a standard normal distribution.

Confidence levelTail area each sideCritical value \(z^*\)
80%0.101.282
90%0.051.645
95%0.0251.960
98%0.012.326
99%0.0052.576
One-proportion z interval: conditions
  • Random: the data come from a random sample or a randomized experiment.
  • Independence: observations are independent; when sampling without replacement, \(n\) is less than 10 percent of the population.
  • Large counts: at least 10 successes and at least 10 failures in the sample: \(n\hat{p} \ge 10\) and \(n(1-\hat{p}) \ge 10\). (We use \(\hat{p}\) here because \(p\) is unknown.)

If the counts are too small, the plain interval can miss its stated level badly. Use the plus-four interval below instead.

Example 9.1: A 95 percent interval for a proportion

A random sample of \(n = 400\) adults in a large city is surveyed (hypothetical data), and 172 say they support a proposed transit tax. Find and interpret a 95 percent confidence interval for the proportion of all adults in the city who support it.

Conditions. Random sample; 400 is far less than 10 percent of a large city; successes \(= 172\) and failures \(= 228\), both at least 10.

Estimate. \(\hat{p} = 172/400 = 0.43\). \(\text{SE} = \sqrt{0.43(0.57)/400} = 0.02475\).

Interval. Margin of error \(= 1.96 \times 0.02475 = 0.0485\), so the interval is \(0.43 \pm 0.0485\), that is, \((0.381,\ 0.479)\).

Interpretation. We are 95 percent confident that between 38.1 and 47.9 percent of all adults in the city support the tax. Note that the interval lies entirely below 50 percent: this sample gives good evidence the measure does not have majority support.

Going deeper: The plus-four and Wilson intervals

The interval above (called the Wald interval) plugs \(\hat{p}\) into the standard error. When \(p\) is near 0 or 1, or \(n\) is small, its true coverage can be far below the stated level: a nominal 95 percent interval may capture the parameter only 85 to 90 percent of the time. The reason is that the sampling distribution of \(\hat{p}\) is skewed there, and the estimated standard error is unreliable when \(\hat{p}\) is close to 0.

The plus-four interval (Agresti and Coull) adds two successes and two failures to the data and then uses the Wald formula: \(\tilde{p} = (x + 2)/(n + 4)\), interval \(\tilde{p} \pm z^*\sqrt{\tilde{p}(1-\tilde{p})/(n+4)}\). It pulls the estimate slightly toward 0.5 and has much better coverage, even for small samples and extreme proportions. The Wilson score interval solves \(|\hat{p} - p| = z^* \sqrt{p(1-p)/n}\) for \(p\) and is the standard recommendation in the statistical literature:

\[\frac{\hat{p} + \frac{z^{*2}}{2n} \pm z^*\sqrt{\frac{\hat{p}(1-\hat{p})}{n} + \frac{z^{*2}}{4n^2}}}{1 + z^{*2}/n}.\]

The coverage simulator above lets you compare all three: choose "Proportion" and a small \(n\) or a small \(p\).

9.3

The t distribution and intervals for a mean

For a mean we would like to use \(\bar{x} \pm z^*\,\sigma/\sqrt{n}\), but we almost never know \(\sigma\). Substituting the sample standard deviation \(s\) adds a second source of randomness, since \(s\) also varies from sample to sample. The standardized statistic

\[t = \frac{\bar{x} - \mu}{s/\sqrt{n}}\]

is then no longer standard normal. William Gosset (writing as "Student") showed in 1908 that, for a normal population, it follows a t distribution with \(n - 1\) degrees of freedom (df).

Properties of the t distribution
  • Symmetric and bell shaped, centered at 0, like the standard normal, but with heavier tails: it allows for the extra uncertainty from estimating \(\sigma\).
  • There is a different curve for each \(\text{df} = n - 1\). Small df gives heavy tails; as df grows the t curve approaches the standard normal (for df above 30 the two are very close).
  • Because the tails are heavier, the critical value \(t^*\) is larger than \(z^*\) for the same confidence level, making the interval wider. The penalty for not knowing \(\sigma\) shrinks as \(n\) grows.
One-sample t interval for a mean \[\bar{x} \;\pm\; t^*\,\frac{s}{\sqrt{n}}, \qquad \text{df} = n - 1.\]

Conditions: (1) random sample or randomized experiment; (2) independence (\(n\) less than 10 percent of the population); (3) the population is approximately normal, or \(n\) is large. In practice: for \(n \lt 15\) the data should show no strong skew or outliers; for \(15 \le n \lt 40\) mild skew is acceptable but not strong skew or outliers; for \(n \ge 40\) the CLT usually rescues us unless the data are extremely skewed. Always plot the data first.

Example 9.2: A t interval for a mean

A tester measures the battery life (in hours) of 10 randomly selected tablets of one model (synthetic data): 7.2, 8.1, 6.9, 7.8, 8.4, 7.5, 6.6, 8.0, 7.7, 7.1. Find a 95 percent confidence interval for the mean battery life of this model.

Check the data. A dotplot shows no outliers and no strong skew, so a t interval is reasonable for \(n = 10\).

Summaries. \(\bar{x} = 7.53\), \(s = 0.5736\), \(\text{SE} = 0.5736/\sqrt{10} = 0.1814\).

Critical value. \(\text{df} = 9\); for 95 percent confidence \(t^* = 2.262\) (compared with \(z^* = 1.960\)).

Interval. Margin of error \(= 2.262 \times 0.1814 = 0.4103\); the interval is \(7.53 \pm 0.41 = (7.12,\ 7.94)\) hours.

Interpretation. We are 95 percent confident that the mean battery life for this model is between 7.12 and 7.94 hours. Had we wrongly used \(z^*\), we would have reported \((7.17,\ 7.89)\), an interval that is too narrow and captures the mean less than 95 percent of the time.

Where the "n - 1" comes from

The sample deviations \(x_i - \bar{x}\) always sum to zero, so once \(n - 1\) of them are known the last is determined: only \(n - 1\) pieces of information about spread are free. That is why \(s\) divides by \(n - 1\) and why the t distribution has \(n - 1\) degrees of freedom.

9.4

What controls the margin of error

The margin of error \(\text{ME} = (\text{critical value}) \times (\text{standard error})\) responds to three things:

ChangeEffect on the margin of errorWhy
Higher confidence levelLarger (wider interval)A bigger critical value is needed to capture more of the distribution: the price of more confidence is less precision.
Larger sample size \(n\)SmallerThe standard error shrinks like \(1/\sqrt{n}\): four times the data halves the margin of error.
More variability (\(\sigma\) or \(p(1-p)\) larger)LargerNoisier data give a noisier estimate.
The margin of error covers only sampling variability

A confidence interval accounts for the random error from sampling. It does not protect against bias: undercoverage, non-response, leading questions, or measurement error (Chapter 2). A poll that reaches only landline users can be off by far more than its "plus or minus 3 points," and the interval will not warn you.

9.5

Choosing the sample size

Before collecting data we can decide how large a sample is needed to achieve a desired margin of error \(m\). Solve the margin of error formula for \(n\).

Sample size formulas (round up)
  • Mean: \(n = \left(\dfrac{z^*\sigma}{m}\right)^2\), where \(\sigma\) is a planning value (from a pilot study, past data, or the range divided by 4).
  • Proportion: \(n = \dfrac{z^{*2}\,p^*(1-p^*)}{m^2}\), where \(p^*\) is a planning value. If nothing is known use \(p^* = 0.5\), which maximizes \(p^*(1-p^*)\) and so gives a sample size that is safe for any true \(p\).

Always round up to the next whole number. (For a mean, the formula uses \(z^*\) because the t critical value depends on \(n\), which is not yet known; add a few observations if \(n\) comes out small.)

Example 9.3: Sample size for a poll

A polling company wants a 95 percent margin of error of at most 3 percentage points (\(m = 0.03\)) with no prior information about \(p\). Use \(p^* = 0.5\):

\[n = \frac{1.96^2 (0.5)(0.5)}{0.03^2} = \frac{0.9604}{0.0009} = 1067.1 \;\Rightarrow\; n = 1068.\]

If past polls suggest \(p\) is around 0.2, then \(n = 1.96^2(0.2)(0.8)/0.03^2 = 682.95 \Rightarrow 683\), a much smaller sample. Halving the margin of error to 1.5 points would need four times as many respondents (about 4,270), not twice as many.

Example 9.4: Sample size for a mean

A researcher wants to estimate mean systolic blood pressure of a population to within \(\pm 2\) mmHg with 95 percent confidence. A pilot study suggests \(\sigma \approx 12\). Then \(n = (1.96 \times 12/2)^2 = 11.76^2 = 138.3\), so \(n = 139\).

9.6

Bootstrap confidence intervals

The formulas above rest on the sampling distribution of a statistic. For \(\bar{x}\) and \(\hat{p}\) we know it (normal or t). For a median, a trimmed mean, a standard deviation, or a ratio, no simple formula is available. The bootstrap (Bradley Efron, 1979) estimates the sampling distribution by computer, using only the data in hand.

The bootstrap percentile interval
  1. Treat the sample as a stand-in for the population.
  2. Draw a bootstrap sample: \(n\) values chosen with replacement from the original \(n\) values (so some appear several times and some not at all).
  3. Compute the statistic (mean, median, \(s\), ...) on the bootstrap sample.
  4. Repeat thousands of times to build the bootstrap distribution.
  5. A 95 percent percentile interval runs from the 2.5th to the 97.5th percentile of the bootstrap distribution.

The bootstrap distribution is centered near the sample statistic (not the parameter), but its spread approximates the standard error of the statistic. That is enough to build an interval.

Example 9.5: A small skewed sample

Twelve customer waiting times in minutes (synthetic): 2.1, 3.4, 1.8, 12.6, 4.2, 2.9, 7.7, 3.1, 15.3, 2.4, 5.6, 3.8. The data are right skewed with two large values, so the t conditions are doubtful for \(n = 12\).

Sample mean \(5.41\), median \(3.60\), \(s = 4.34\). The t interval for the mean is \(5.41 \pm 2.201(1.254) = (2.65,\ 8.17)\). A bootstrap percentile interval for the mean (many thousands of resamples) is about \((3.3,\ 8.0)\): narrower, and shifted to the upper side because the bootstrap distribution inherits the right skew. For the median no textbook formula exists, but the bootstrap gives about \((2.7,\ 6.7)\). Load these data in the bootstrap lab below and try the different statistics.

Limits of the bootstrap

The bootstrap is not magic. It cannot fix a biased sample, and for very small samples the percentile interval tends to be a little too narrow (in Example 9.5 it is narrower than the t interval). It works best for moderate to large samples and smooth statistics. It also fails for statistics like the maximum. Its great strength is that it applies to almost any statistic with almost no formulas.

9.7

Chapter summary

Key ideas and formulas
  • Interval = point estimate \(\pm\) (critical value)(standard error). The confidence level is the long-run success rate of the method.
  • Proportion: \(\hat{p} \pm z^*\sqrt{\hat{p}(1-\hat{p})/n}\). Need at least 10 successes and 10 failures. Use plus-four (or Wilson) for small counts.
  • Mean: \(\bar{x} \pm t^* s/\sqrt{n}\) with \(\text{df} = n - 1\). Check for strong skew and outliers when \(n\) is small.
  • Higher confidence gives a wider interval; more data gives a narrower interval (\(\propto 1/\sqrt{n}\)); more variability gives a wider interval.
  • Sample size: \(n = (z^*\sigma/m)^2\) for a mean, \(n = z^{*2}p^*(1-p^*)/m^2\) for a proportion (use \(p^* = 0.5\) if unknown); round up.
  • Bootstrap percentile interval: resample with replacement, compute the statistic, take the middle 95 percent.
  • Never say "the probability that \(\mu\) is in the interval is 95 percent" once the interval is computed. Intervals do not cover bias.

Key terms

TermMeaning
Point estimateA single number used to estimate a parameter
Confidence intervalInterval from a method that captures the parameter in a stated proportion of repeated samples
Confidence levelThat stated proportion (90%, 95%, 99%)
Margin of errorCritical value times standard error: half the interval width
Critical value\(z^*\) or \(t^*\): boundary capturing the central \(C\) percent
t distributionHeavy-tailed bell curve indexed by degrees of freedom, used when \(\sigma\) is estimated
BootstrapResampling the data with replacement to approximate a sampling distribution
9.8

Practice