# Statistical Inference: MLE, MAP Estimation, Confidence Intervals & Hypothesis Testing
Exam: GATE Data Science & Artificial Intelligence (DA) (GATE DA)
Subject: Data Science, Statistics & Data Warehousing
Canonical URL: https://gateandnet.com/exams/gate-da/data-science/mle-map-estimation-and-hypothesis-testing

> Maximum Likelihood vs Maximum A Posteriori derivations (Bernoulli/Beta & Gaussian priors), unbiased sample variance Bessel correction (n-1), Z vs t tests, p-values, and Type-I/II errors.

## 1. Worked MLE & Conjugate MAP Derivations

1. **Bernoulli Coin ($k$ Heads in $n$ Flips) with $\operatorname{Beta}(\alpha, \beta)$ Prior:**
   - **MLE:** $\hat{p}_{\text{MLE}} = \frac{k}{n}$ (if $n=3, k=3 \implies \hat{p}_{\text{MLE}} = 1.0$, extreme small-sample overfitting!).
   - **MAP with $p \sim \operatorname{Beta}(\alpha, \beta) \propto p^{\alpha-1}(1-p)^{\beta-1}$:**
     $$\hat{p}_{\text{MAP}} = \frac{k + \alpha - 1}{n + \alpha + \beta - 2}, \qquad \mathbb{E}[p \mid D]_{\text{Posterior Mean}} = \frac{k + \alpha}{n + \alpha + \beta}$$
     Notice $\alpha, \beta$ act as **pseudo-counts** (Laplace smoothing corresponds to posterior mean under uniform $\operatorname{Beta}(1,1)$!).
2. **Linear Regression Probabilistic Equivalence:**
   - Gaussian noise $y \mid x \sim \mathcal{N}(w^T x, \sigma^2)$ + **Gaussian prior** $w_j \sim \mathcal{N}(0, \tau^2) \iff$ **$L_2$ Ridge Regression** ($\lambda = \sigma^2 / \tau^2$).
   - Gaussian noise + **Laplace prior** $p(w_j) \propto e^{-|w_j|/b} \iff$ **$L_1$ Lasso Regression**!

## 2. Hypothesis Testing, $p$-Values & Test Selection Matrix

| Statistical Test | Distributional Setup | Test Statistic |
| :--- | :--- | :--- |
| **One/Two-Sample $Z$-Test** | Population variance $\sigma^2$ **known** (or large $n \ge 30$ via CLT) | $Z = \frac{\bar{X} - \mu_0}{\sigma / \sqrt{n}} \sim \mathcal{N}(0,1)$ |
| **Student’s $t$-Test** | Gaussian population with $\sigma^2$ **unknown**, estimated by $S^2$ | $T = \frac{\bar{X} - \mu_0}{S / \sqrt{n}} \sim t_{n-1}$ |
| **Chi-Square ($\chi^2$) Test** | Categorical goodness-of-fit or contingency table independence | $\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}$ |
| **One-Way ANOVA ($F$-Test)** | Comparing means across **$k \ge 3$** groups simultaneously | $F = \frac{\text{MS}_{\text{between}}}{\text{MS}_{\text{within}}}$ |

> [!TRAP]
> **What a $p$-Value Is (and Is NOT!):** The $p$-value is $P(\text{test statistic at least as extreme as observed} \mid H_0 \text{ is TRUE})$ — it is **NEVER** $P(H_0 \text{ is true} \mid \text{data})$! Similarly, a $95\%$ Frequentist Confidence Interval means $95\%$ of repeated random intervals cover the fixed true $\theta$.

## Solved Practice Questions & PYQs

### [GATE DA Stats | MCQ]
A biased coin with Heads probability $\theta$ has prior $\theta \sim \operatorname{Beta}(2, 2)$. In $n = 6$ independent tosses, you observe $k = 5$ Heads and $1$ Tail. What are $\hat{\theta}_{\text{MLE}}$ and $\hat{\theta}_{\text{MAP}}$?
**Correct Answer:** A
**Solution:** - $\hat{\theta}_{\text{MLE}} = \frac{k}{n} = \mathbf{\frac{5}{6}}$.
- Mode of posterior $\operatorname{Beta}(k + \alpha,\; n - k + \beta) = \operatorname{Beta}(7, 3)$ is $\hat{\theta}_{\text{MAP}} = \frac{k + \alpha - 1}{n + \alpha + \beta - 2} = \frac{5 + 2 - 1}{6 + 2 + 2 - 2} = \frac{6}{8} = \mathbf{\frac{3}{4}}$.

### [GATE DA Stats | MCQ]
In classical Frequentist Hypothesis Testing, **Rejecting a True Null Hypothesis ($H_0$)** and **Failing to Reject a False Null Hypothesis ($H_0$)** are respectively called:
**Correct Answer:** A
**Solution:** False Positive (rejecting true $H_0$) = **Type-I Error** with probability $\alpha$ (level of significance). False Negative (failing to reject false $H_0$) = **Type-II Error** with probability $\beta$ (while $1 - \beta$ is **Statistical Power**).
