j-devlog
KO
~/nav

// categories

// tags

[MMD]

ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing

·14 min read·

In Chapter 3 we covered MLE and MAP for estimating population parameters from samples. This chapter focuses on quantifying the uncertainty of those estimates with confidence intervals, and on hypothesis testing — using data to validate statistical claims.


1. Confidence Intervals#

What Is a Confidence Interval?#

A point estimate reduces a parameter to a single value. But because samples always vary, interval estimation is more informative.

Confidence Interval (CI): a range of values expected to contain the true parameter


xˉ±margin of error\bar{x} \pm \text{margin of error}


  • 95% CI: if you repeat the same experiment 100 times, roughly 95 of the resulting intervals will contain the population mean
  • A CI is not the probability that the parameter lies in this particular interval — the parameter is fixed; it's the interval that changes

Margin of Error#

ME=zσn\text{ME} = z^* \cdot \frac{\sigma}{\sqrt{n}}

Confidence Levelzz^*
90%1.645
95%1.960
99%2.576

Effect of sample size: larger nn shrinks σn\frac{\sigma}{\sqrt{n}}, producing a narrower (more precise) CI.

Steps to compute a CI:

  1. Calculate the point estimate (xˉ\bar{x})
  2. Choose a confidence level → determine zz^*
  3. Compute the standard error: SE=σnSE = \frac{\sigma}{\sqrt{n}}
  4. Build the CI: xˉ±zSE\bar{x} \pm z^* \cdot SE

When the Population SD Is Unknown — the t-Distribution#

In practice, σ\sigma is almost never known. Substituting the sample standard deviation ss introduces additional uncertainty, so we use the t-distribution instead.


t=xˉμs/nt = \frac{\bar{x} - \mu}{s/\sqrt{n}}


  • Degrees of freedom (df) = n1n - 1
  • Smaller nn → heavier tails (reflecting greater uncertainty)
  • As nn grows, the t-distribution converges to the standard normal

CI using the t-distribution:


xˉ±tn1sn\bar{x} \pm t^*_{n-1} \cdot \frac{s}{\sqrt{n}}

Confidence Interval for a Proportion#

Estimating the population proportion pp from binary outcomes (success/failure):


p^±zp^(1p^)n\hat{p} \pm z^* \cdot \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}


Conditions for the normal approximation to hold: np^10n\hat{p} \geq 10 and n(1p^)10n(1-\hat{p}) \geq 10


2. Hypothesis Testing#

Null and Alternative Hypotheses#

Description
Null hypothesis H0H_0No effect, no difference — the "default assumption"
Alternative hypothesis H1H_1The claim we are trying to establish

Example:

  • H0H_0: The new drug and the existing drug are equally effective (μ1=μ2\mu_1 = \mu_2)
  • H1H_1: The new drug is more effective (μ1>μ2\mu_1 > \mu_2)

Types of Errors#

H0H_0 is TrueH0H_0 is False
RejectType I Error (False Positive)Correct decision
Fail to rejectCorrect decisionType II Error (False Negative)
  • Type I error rate = significance level α\alpha (typically 0.05)
  • Type II error rate = β\beta
  • Statistical Power = 1β1 - \beta (probability of correctly rejecting a false H0H_0)

Significance Level#

α\alpha is the maximum tolerated probability of a Type I error.

  • α=0.05\alpha = 0.05: when H0H_0 is true, we incorrectly reject it 5% of the time
  • Lowering α\alpha reduces Type I errors but increases Type II errors

One-Tailed vs. Two-Tailed Tests#

Test TypeH1H_1Rejection Region
Right-tailedμ>μ0\mu > \mu_0Right tail
Left-tailedμ<μ0\mu < \mu_0Left tail
Two-tailedμμ0\mu \neq \mu_0Both tails

In a two-tailed test, α\alpha is split evenly between the tails, placing α/2\alpha/2 in each.

p-value#

p-value: the probability of observing a test statistic at least as extreme as the one obtained, assuming H0H_0 is true


p-value<αReject H0p\text{-value} < \alpha \Rightarrow \text{Reject } H_0 p-valueαFail to reject H0 (not the same as "accepting" it)p\text{-value} \geq \alpha \Rightarrow \text{Fail to reject } H_0 \text{ (not the same as "accepting" it)}

Note: A small p-value means "this result would be unlikely by chance alone" — suggesting the effect is likely real.

Rejection Region and Critical Values#

Critical value: the boundary of the test statistic that corresponds to α\alpha

If the test statistic falls in the rejection region, we reject H0H_0.

Example: two-tailed test, α=0.05\alpha = 0.05 → reject if z<1.96z < -1.96 or z>1.96z > 1.96

Statistical Power#

Power=P(reject H0H1 is true)=1β\text{Power} = P(\text{reject } H_0 \mid H_1 \text{ is true}) = 1 - \beta


To increase power:

  • Increase the sample size nn
  • Increase α\alpha (accept more Type I error)
  • A larger effect size naturally increases power

3. t-Tests#

One-Sample t-Test#

Tests whether a single sample mean differs from a specified value μ0\mu_0.


t=xˉμ0s/n,df=n1t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}, \quad df = n-1


Example: "Is the average score of this class equal to 70?"

Independent Two-Sample t-Test#

Tests whether the means of two independent groups differ.


t=(xˉ1xˉ2)0s12n1+s22n2t = \frac{(\bar{x}_1 - \bar{x}_2) - 0}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}


  • Degrees of freedom: computed via Welch's approximation (for unequal variances)
  • H0H_0: μ1=μ2\mu_1 = \mu_2

Two-Sample Proportion Test#

Tests whether the proportions of two groups differ.


z=(p^1p^2)p^(1p^)(1n1+1n2)z = \frac{(\hat{p}_1 - \hat{p}_2)}{\sqrt{\hat{p}(1-\hat{p})\left(\frac{1}{n_1} + \frac{1}{n_2}\right)}}


where p^\hat{p} is the pooled proportion:


p^=x1+x2n1+n2\hat{p} = \frac{x_1 + x_2}{n_1 + n_2}

Paired t-Test#

Tests the mean difference between before-and-after measurements on the same subjects.


di=xi,afterxi,before,t=dˉsd/nd_i = x_{i,\text{after}} - x_{i,\text{before}}, \quad t = \frac{\bar{d}}{s_d/\sqrt{n}}


Example: change in blood pressure before and after taking a medication — each patient serves as their own control.


4. A/B Testing#

A/B testing is the practical application of the two-sample test framework.

Procedure:

  1. Set up H0H_0: the conversion rates of A and B are equal
  2. Choose a significance level α\alpha (typically 0.05)
  3. Collect sufficient data (determine sample size based on desired power)
  4. Compute the test statistic
  5. Check the p-value → decide whether to reject H0H_0

Common pitfalls:

  • Multiple comparisons problem: testing many metrics simultaneously inflates the Type I error rate → apply Bonferroni correction or similar adjustments
  • No early stopping: stopping the experiment the moment results look significant dramatically increases False Positives
  • Practical vs. statistical significance: a tiny p-value doesn't automatically mean the effect is meaningful — always check the effect size

Summary#

ConceptKey Point
Confidence Intervalxˉ±zSE\bar{x} \pm z^* \cdot SE — estimates a range for the parameter
t-DistributionUsed when σ\sigma is unknown; df = n1n-1
p-valueProbability of observing the data (or more extreme) under H0H_0
Type I Errorα\alpha — rejecting a true H0H_0
Type II Errorβ\beta — failing to reject a false H0H_0
Statistical Power1β1 - \beta — ability to detect a real effect
Paired t-TestCompares before-and-after measurements on the same subjects

Quiz#

Q1. Which statement correctly interprets a 95% confidence interval?

a) There is a 95% probability that the population mean lies within this interval. b) If the experiment is repeated many times, about 95% of the resulting intervals will contain the population mean. c) There is a 95% probability that the sample mean lies within this interval. d) 95% of the sample values fall within this interval.

Show Answer

Answer: b

A confidence interval does not express the probability that the parameter is in this specific interval. The parameter is fixed; it's the interval that varies from sample to sample. A 95% CI means: "if we construct intervals using this procedure repeatedly, roughly 95 out of 100 will contain the true parameter."


Q2. Why do we use the t-distribution instead of the z-distribution?

a) When the sample follows a normal distribution b) When the population standard deviation σ\sigma is unknown and we substitute ss c) When the sample size is 30 or more d) When analyzing binary data

Show Answer

Answer: b

Replacing σ\sigma with ss introduces additional uncertainty. The t-distribution accounts for this with heavier tails, and converges to the standard normal as the sample size grows.


Q3. If the p-value is 0.03 and the significance level is α=0.05\alpha = 0.05, what is the correct conclusion?

a) Accept the null hypothesis. b) The alternative hypothesis is false. c) Reject the null hypothesis. d) No conclusion can be drawn.

Show Answer

Answer: c

Since p-value (0.03) < α\alpha (0.05), we reject H0H_0. Note: this does not "prove" H0H_0 is false — it means the observed data are sufficiently inconsistent with H0H_0 to warrant rejection.


Q4. When is a paired t-test more appropriate than an independent two-sample t-test?

a) When the two groups have different sample sizes b) When comparing before-and-after measurements from the same subjects c) When both groups have equal variances d) When the sample size is large

Show Answer

Answer: b

Before-and-after measurements on the same subject are not independent. By computing the difference (did_i), we remove between-subject variability, which increases statistical power. Example: comparing a patient's blood pressure before and after treatment.


Q5. Why is "early stopping" a problem in A/B testing?

a) Because the sample size grows too large b) Because repeatedly testing at every time point inflates the Type I error rate well above the nominal α\alpha c) Because a z-distribution should be used instead of a t-distribution d) Because statistical power decreases

Show Answer

Answer: b

Continuously monitoring interim results and stopping as soon as they appear significant creates a multiple comparisons problem. Even when there is no real effect, the probability of observing a spuriously significant result far exceeds α\alpha.


The next chapter covers Information Theory — entropy, cross-entropy, KL divergence, and the mathematical foundations behind the loss functions used in machine learning.

// Related Posts