[MMD]
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
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
- 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#
| Confidence Level | |
|---|---|
| 90% | 1.645 |
| 95% | 1.960 |
| 99% | 2.576 |
Effect of sample size: larger shrinks , producing a narrower (more precise) CI.
Steps to compute a CI:
- Calculate the point estimate ()
- Choose a confidence level → determine
- Compute the standard error:
- Build the CI:
When the Population SD Is Unknown — the t-Distribution#
In practice, is almost never known. Substituting the sample standard deviation introduces additional uncertainty, so we use the t-distribution instead.
- Degrees of freedom (df) =
- Smaller → heavier tails (reflecting greater uncertainty)
- As grows, the t-distribution converges to the standard normal
CI using the t-distribution:
Confidence Interval for a Proportion#
Estimating the population proportion from binary outcomes (success/failure):
Conditions for the normal approximation to hold: and
2. Hypothesis Testing#
Null and Alternative Hypotheses#
| Description | |
|---|---|
| Null hypothesis | No effect, no difference — the "default assumption" |
| Alternative hypothesis | The claim we are trying to establish |
Example:
- : The new drug and the existing drug are equally effective ()
- : The new drug is more effective ()
Types of Errors#
| is True | is False | |
|---|---|---|
| Reject | Type I Error (False Positive) | Correct decision |
| Fail to reject | Correct decision | Type II Error (False Negative) |
- Type I error rate = significance level (typically 0.05)
- Type II error rate =
- Statistical Power = (probability of correctly rejecting a false )
Significance Level#
is the maximum tolerated probability of a Type I error.
- : when is true, we incorrectly reject it 5% of the time
- Lowering reduces Type I errors but increases Type II errors
One-Tailed vs. Two-Tailed Tests#
| Test Type | Rejection Region | |
|---|---|---|
| Right-tailed | Right tail | |
| Left-tailed | Left tail | |
| Two-tailed | Both tails |
In a two-tailed test, is split evenly between the tails, placing in each.
p-value#
p-value: the probability of observing a test statistic at least as extreme as the one obtained, assuming is true
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
If the test statistic falls in the rejection region, we reject .
Example: two-tailed test, → reject if or
Statistical Power#
To increase power:
- Increase the sample size
- Increase (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 .
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.
- Degrees of freedom: computed via Welch's approximation (for unequal variances)
- :
Two-Sample Proportion Test#
Tests whether the proportions of two groups differ.
where is the pooled proportion:
Paired t-Test#
Tests the mean difference between before-and-after measurements on the same subjects.
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:
- Set up : the conversion rates of A and B are equal
- Choose a significance level (typically 0.05)
- Collect sufficient data (determine sample size based on desired power)
- Compute the test statistic
- Check the p-value → decide whether to reject
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#
| Concept | Key Point |
|---|---|
| Confidence Interval | — estimates a range for the parameter |
| t-Distribution | Used when is unknown; df = |
| p-value | Probability of observing the data (or more extreme) under |
| Type I Error | — rejecting a true |
| Type II Error | — failing to reject a false |
| Statistical Power | — ability to detect a real effect |
| Paired t-Test | Compares 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 is unknown and we substitute c) When the sample size is 30 or more d) When analyzing binary data
Show Answer
Answer: b
Replacing with 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 , 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) < (0.05), we reject . Note: this does not "prove" is false — it means the observed data are sufficiently inconsistent with 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 (), 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 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 .
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
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 3: Sampling, MLE, and MAP
A concise guide to the core ideas behind ML estimation: populations vs. samples, the Law of Large Numbers, the Central Limit Theorem, Maximum Likelihood Estimation (MLE), Maximum A Posteriori (MAP), and regularization.