Chapter 06 · Inference

Confidence Intervals

A single number pretends to be exact. A confidence interval says how far off it could reasonably be. This is the most useful tool in the course: every estimate you report should travel with one.

~35 min Data: NCS wildcats (drilling days, outcomes) · EIA refinery utilisation · Brent monthly returns

In 60 seconds

  • Interval = estimate ± margin of error; margin = (critical value) × (standard error).
  • "95 % confidence" describes the method: 95 % of intervals built this way contain the true value.
  • For a mean with unknown σ use the t-interval; for a proportion, the z-interval (or plus-four for small samples).
  • Wider for more confidence or more variability; narrower with larger samples (by √n).

Point estimate → interval estimate

A point estimate is a single statistic used for a parameter: x̄ for μ, p̂ for p, s for σ. Chapter 05 showed that x̄ wanders around μ with standard error σ/√n and is roughly normal. So 95 % of the time x̄ lands within 1.96 standard errors of μ — which means the interval x̄ ± 1.96·σ/√n catches μ 95 % of the time.

Anatomy of a confidence interval point estimate x̄ margin of error E margin of error E x̄ − E x̄ + E E = (critical value) × (standard error)

What "95 % confident" really means

The population below is every Norwegian wildcat with a recorded drilling time — so we know the true mean μ. Draw 100 random samples, build a 95 % t-interval from each, and count how many miss.

Try it: 100 confidence intervals

Each horizontal line is one interval. Orange = missed μ.

The most common misreading

After computing one interval, it is not correct to say "μ is in this interval with probability 0.95". μ is fixed; this particular interval either contains it or not. The 95 % is the long-run hit rate of the procedure — which is what the simulator shows.

z-interval: when σ is known

One-mean z-interval

\bar{x} \pm z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}}

Confidence level 1 − α. z_{0.05} = 1.645 (90 %), z_{0.025} = 1.96 (95 %), z_{0.005} = 2.576 (99 %). Requires a normal population or a large n.

The margin of error E = zα/2·σ/√n shows three levers: more confidence → wider; more variability σ → wider; more data n → narrower. Solve for n to plan a study:

Sample size for a target margin E

n = \left(\frac{z_{\alpha/2} \, \sigma}{E}\right)^2 \quad \text{(round up)}

To pin wildcat drilling time to ±3 days at 95 % with σ ≈ 25 days: n = (1.96 × 25 / 3)² = 266.8 → 267 wells.

t-interval: the everyday case

σ is almost never known. Replacing it by s adds uncertainty, so the standardised statistic (x̄ − μ)/(s/√n) follows Student's t-distribution with n − 1 degrees of freedom: bell-shaped and centered at 0 like z, but with heavier tails — heavier the smaller the sample.

t-curves approach the standard normal as df grows

Density · df = 2, 5 and 30 vs z

One-mean t-interval

\bar{x} \pm t_{\alpha/2} \cdot \frac{s}{\sqrt{n}}, \qquad df = n - 1

Assumes a random sample from a normal population, or n large. Robust to moderate non-normality, sensitive to outliers in small samples.

Wildcats 2015–2024

295
wells with drilling time

Mean drilling time

39.3 d
s = 24.9 days

t0.025, df = 294

1.968
vs z = 1.960

95 % CI for μ

36.4 – 42.1
days

Which interval procedure?

Choosing z, t or a nonparametric method Outliers?look at a boxplot Investigate firsterror? keep? nonparametric σ known?rare in practice z-interval t-interval small n & skewed?bootstrap (ch 12) yes no yes no

Confidence interval for a proportion

One-proportion z-interval

\hat{p} \pm z_{\alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}

Use when x and n − x are both at least 5.

Plus-four interval

\tilde{p} = \frac{x + 2}{n + 4}, \qquad \tilde{p} \pm z_{\alpha/2} \sqrt{\frac{\tilde{p}(1 - \tilde{p})}{n + 4}}

Add 2 successes and 2 failures. Much better coverage for small samples.

Sample size

n = \hat{p}_g (1 - \hat{p}_g) \left(\frac{z_{\alpha/2}}{E}\right)^2

Without a guess \hat{p}_g, use 0.5 (worst case): n = 0.25\,(z_{\alpha/2}/E)^2.

Norwegian wildcats spudded 2015–2024: 150 discoveries in 295 wells, p̂ = 0.508. 95 % CI: 45.1% to 56.6% (plus-four: 45.2% to 56.5%). Pinning the rate to ±5 points needs about 385 wells — more than a decade of Norwegian drilling.

Proportion interval calculator

Confidence interval for a standard deviation

Risk is about spread, not just level. If the variable is normal, (n − 1)s²/σ² follows a χ² (chi-square) distribution with n − 1 df — right-skewed, always positive, approaching normal for large df. Inverting it gives an interval for σ:

χ²-interval for σ

\sqrt{\frac{(n - 1)\, s^2}{\chi^2_{\alpha/2}}} \quad \text{to} \quad \sqrt{\frac{(n - 1)\, s^2}{\chi^2_{1 - \alpha/2}}}

Note the swap: the larger χ² value gives the lower limit.

Brent monthly returns since 1987: s = 10.02 % from n = 473 months; 95 % χ²-interval for the volatility σ: 9.42 % to 10.71 %.

Not robust

Unlike the t-interval, the χ² procedure for σ is very sensitive to non-normality — and chapter 04 showed oil returns have fat tails. Treat this interval as too narrow; chapter 12 builds a bootstrap interval that does not need normality.

Do it in code

from scipy import stats
from statsmodels.stats.proportion import proportion_confint
d = wells.query("2015 <= entry_year <= 2024").drilling_days.dropna()
stats.t.interval(0.95, df=len(d)-1, loc=d.mean(), scale=stats.sem(d))   # (36.43, 42.13)
proportion_confint(150, 295, alpha=0.05, method="normal")                # (0.451, 0.566)
s, n = r_month.std(ddof=1), len(r_month)
np.sqrt((n-1)*s**2 / stats.chi2.ppf([0.975, 0.025], n-1))               # (9.42, 10.71)
select count(*)                                   as n,
       avg(drilling_days)                         as xbar,
       stddev_samp(drilling_days)                 as s,
       stddev_samp(drilling_days) / sqrt(count(*)) as se       -- multiply by t(0.025, n-1) = 1.968
from v_wildcats
where entry_year between 2015 and 2024 and drilling_days is not null;

Key takeaways

  • Report estimates as intervals: estimate ± critical value × standard error.
  • Confidence is a property of the method's long-run hit rate.
  • Use t when σ is unknown (almost always); the z-interval for proportions; plus-four for small samples.
  • Precision costs data quadratically: halving the margin needs four times the sample.

Self-check

1 · Interpret

Interpret the interval 36.4 – 42.1 days for the mean wildcat drilling time.

Answer

We are 95 % confident that the mean drilling time of Norwegian wildcats of this era lies between 36.4 and 42.1 days — "confident" meaning the method captures the true mean in 95 % of samples.

2 · Wider or narrower?

What happens to the interval if you move from 95 % to 99 % confidence? If you double n?

Answer

99 %: wider (z from 1.96 to 2.576, about 31 % wider). Doubling n: narrower by a factor 1/√2 ≈ 0.71.

3 · Plan the survey

You want the share of a refinery's 400 pumps with seal leaks to within ±4 points at 95 %, no prior guess. How many pumps to inspect?

Answer

n = 0.25 × (1.96/0.04)² = 600.25 → 601. That is more than all 400 pumps, so inspect them all (or accept a wider margin; with a finite population correction the requirement drops, but a census is simplest).