Chuyển đến nội dung

Bài 33 · Sampling and Inference Basics

Confidence Intervals

Build 95% confidence intervals for means and proportions, interpret them correctly, understand margin of error, and see coverage in a simulation.

A sample mean is a single guess for the unknown population mean. A better statement gives a range of plausible values and says how reliable the method is. That range is a confidence interval.

It uses the standard error from sampling distributions and the z-values from z-scores.

The recipe

Text
estimate ± critical value × standard error

For a mean with a large sample (or a known σ), a 95% interval is:

Text
x̄ ± 1.96 × s/√n

The number 1.96 is the z-value that leaves 2.5% in each tail. The part after ± is the margin of error.

Worked example

A sample of n = 36 students has mean study time x̄ = 72.4 minutes and standard deviation s = 9.

Text
standard error = 9 / √36 = 1.5
margin of error = 1.96 × 1.5 = 2.94
95% interval = 72.4 ± 2.94 = (69.46, 75.34)
Python Confidence interval for a mean

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Higher confidence means a wider interval: you buy certainty with precision.

Small samples: the t distribution

When n is small and σ is estimated by s, the extra uncertainty makes intervals a bit wider. Use critical values from the t distribution with n - 1 degrees of freedom instead of 1.96. For example, the 95% critical value is about 2.262 with 9 degrees of freedom, and about 2.131 with 15. As n grows, t approaches 1.96. In Python, SciPy provides scipy.stats.t.ppf.

Python t critical values approach 1.96

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Confidence interval for a proportion

For a sample proportion p̂ from n people:

Text
p̂ ± z* × √( p̂(1 - p̂) / n )

Example: 540 of 900 voters support a proposal. p̂ = 0.6, SE = √(0.6 × 0.4 / 900) ≈ 0.01633, margin ≈ 0.0320. The 95% interval is about (0.568, 0.632).

How to interpret it

A 95% confidence interval does not say "there is a 95% probability that μ is in this interval". The true μ is a fixed number; it either is or is not inside. The 95% describes the method: if you repeated the sampling many times and built an interval each time, about 95% of those intervals would contain the true value.

Python Simulate the meaning of 95% confidence

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The result should be close to 0.95 (a little below, since using s with 1.96 slightly under-covers at n = 40).

What controls the margin of error?

The margin is z* × σ/√n, so:

  • larger n gives a narrower interval,
  • more variable data gives a wider one,
  • higher confidence gives a wider one.

To plan a survey, you can solve for n. To get a margin of 3 percentage points for a proportion at 95% confidence, using the worst case p = 0.5, you need n ≥ (1.96 × 0.5 / 0.03)² ≈ 1068.

Confidence intervals fix random sampling error only. They do nothing about bias, such as a poorly chosen sample.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. n = 100, x̄ = 40, s = 5. What is the 95% interval (use 1.96)?

    SE = 5/10 = 0.5, and 1.96 × 0.5 = 0.98.
  2. 2. If you change from 95% to 99% confidence with the same data, the interval gets...

    A larger critical value is needed to capture more of the sampling distribution.
  3. 3. The correct interpretation of a 95% confidence interval is...

    The confidence level is a property of the procedure over repeated sampling.
  4. 4. To halve the margin of error you need roughly...

    Margin ∝ 1/√n, so quadrupling n halves it.

Summary

  • A confidence interval is estimate ± critical value × standard error.
  • For means use z (large n) or t (small n); for proportions use √(p̂(1 - p̂)/n).
  • 95% describes the long-run success rate of the method, not one interval.
  • Larger n narrows the interval; higher confidence widens it.

Next: Hypothesis Testing Basics

Theo dõi tiến độ của bạn

Tạo tài khoản miễn phí để đánh dấu bài đã học và tiếp tục từ chỗ bạn dừng lại trên mọi thiết bị.