Maximum Likelihood Estimation

Context: FIT2086_MOC · the unit’s universal fitting engine — turns a [[Parametric Probability Distributions|family ]] plus a sample into a number · quality of that is judged in Estimator Quality (Bias, Variance, MSE), its variability in Sampling Distribution of an Estimator · Fisher, 1920s

Quick Revision

  • 🎯 Objective: pick the that assigns the greatest probability to the data observed.
  • 📦 Core Components: likelihood ➔ NLL .
  • ⚡ Key Constraint: is the negative log-likelihood, so you minimise it — flip a sign and every derivation lands on a maximum of the wrong quantity.

📝 How It Works

1. The three tasks of inference

  • Point estimation ➔ learn one best-fitting parameter value from the data — this note.
  • Interval estimation ➔ quantify accuracy/confidence in that fit (W4 CIs).
  • Hypothesis testing ➔ decide whether a stated claim about the data-generating process is plausible (W5).

2. Why not just minimise squared error

  • The heuristic ➔ choose close to all points under squared error: , so — read as the that minimises , and the hat as “estimator of”.
  • It gives the sample mean — the sample mean is the closest point to the sample in a squared sense.
  • ⚡ Key Constraint: no handle on ➔ squared error scores only the centre; a spread parameter has no obvious goodness-of-fit under it, so a general criterion is needed.

3. The likelihood criterion

  • Goodness-of-fit = probability assigned to the data ➔ score a candidate by ; larger means the observed data is more likely under that model. Read as the likelihood function — a function of with fixed.
  • Independence factorises it for the iid models of this unit.
  • Work with the NLL ➔ products of small probabilities are analytically and numerically horrible; turns them into sums, and because is strictly increasing.
  • Notation; is generic, and for Bernoulli the specific parameter also happens to be called .
  • Status ➔ originally a heuristic, later shown to have strong properties — notably statistical consistency for most models.

4. Product and log identities (the whole algebra of step 2)

  • Constants · .
  • Exponents collapse to sums · .
  • Constant factors pull out.
  • Then log · · · terms free of are constants whose derivative vanishes.

5. Using the fit: the plug-in distribution

  • Plug-in ➔ substitute the estimates back into the family, , and treat it as the population.
  • What it buys ➔ probability statements about the population: for the height data, .
  • Accuracy inherits ➔ the better , the more trustworthy every downstream probability — which is why estimator quality gets its own note.
  • Checking the fit ➔ score the plug-in model on held-out data, comparing predicted probabilities against empirical proportions and ranking models by out-of-sample NLL ➔ Plug-in Prediction and Held-Out Evaluation.

🧮 Proof Blueprint

Theorem (ML recipe). For iid , solves . Strategy: factorise ➔ take ➔ differentiate ➔ set to zero ➔ rearrange.

Derivation — Gaussian , :

Q.E.D. ➔ for the Gaussian the ML estimators are the sample mean and the sample standard deviation (with divisor ). Multiply through by to clear denominators; is substituted before differentiating in , which removes from the equation.

Derivation — Poisson , :

Q.E.D. ➔ the Poisson rate’s MLE is again the sample mean — but this coincidence is not a rule, as the practice derivations below show.

Derivation — Bernoulli , , (Studio 3):

\begin{aligned} p(\mathbf{y}\mid\theta)&=\prod_{i=1}^n\theta^{y_i}(1-\theta)^{1-y_i}=\theta^{m}(1-\theta)^{n-m},\qquad m=\sum_{i=1}^n y_i\\ L(\mathbf{y}\mid\theta)&=-m\log\theta-(n-m)\log(1-\theta)\\ \frac{dL}{d\theta}&=-\frac{m}{\theta}+\frac{n-m}{1-\theta}=-\frac{n\theta-m}{(\theta-1)\theta}=0\;\Rightarrow\;m-n\theta=0\;\Rightarrow\;\hat\theta=\frac{m}{n}=\frac1n\sum_{i=1}^n y_i \end{aligned} $$**Q.E.D.** ➔ the ML success probability is the **fraction of successes**, i.e. the sample mean of the $0/1$ trials. The exponents collapse because $\sum_i y_i=m$ counts the successes and $\sum_i(1-y_i)=n-m$ the failures; the derivative's $\frac{d}{d\theta}\log(1-\theta)=-\frac{1}{1-\theta}$ supplies the sign flip. ## 📊 Worked Numbers | Data | Family | ML estimates | Read-off | | :--- | :--- | :--- | :--- | | $\mathbf{y}=(1.75,1.64,1.81,1.55,1.51,1.67,1.83,1.63,1.72)$, $n=9$ | $N(\mu,\sigma^2)$ | $\hat\mu=1.6789$, $\hat\sigma=0.1032$ ($\hat\sigma^2=0.0107$) | bulk of samples inside $(\hat\mu-2\hat\sigma,\hat\mu+2\hat\sigma)\approx(1.47,1.88)$ | | $\mathbf{y}=(7,9,3,5,3,4,4,9,4,6)$, $n=10$ | $Poi(\lambda)$ | $\hat\lambda=5.4$ | $\hat\lambda=\bar y$, and $E[X]=V[X]=5.4$ under the fit | | same 9 heights | plug-in $N(\hat\mu,\hat\sigma^2)$ | — | $P(1.6<X<1.8)\approx0.664$ | ## ✍️ Practice > [!QUESTION]- Practice 1: $Y_1,\dots,Y_n\sim\mathrm{Exp}(\beta)$ with $p(y\mid\beta)=\beta e^{-\beta y}$. Derive $\hat\beta_{\text{MLE}}$. > > > [!SUCCESS]- Reference solution > > $$ > > \begin{aligned} > > p(\mathbf{y}\mid\beta)&=\prod_{i=1}^n\beta e^{-\beta y_i}=\beta^n e^{-\beta\sum_i y_i}\\ > > L(\mathbf{y}\mid\beta)&=-n\log\beta+\beta\sum_i y_i\\ > > \frac{dL}{d\beta}&=-\frac{n}{\beta}+\sum_i y_i=0\;\Rightarrow\;\hat\beta=\frac{n}{\sum_i y_i}=\frac{1}{\bar y} > > \end{aligned} > > $$ > > - **Key move:** $\prod e^{-\beta y_i}=e^{-\beta\sum y_i}$ ➔ the estimator is the **reciprocal** of the sample mean, not the sample mean. > [!QUESTION]- Practice 2: pollination rates $X_1,\dots,X_n$ have $f(x\mid\theta)=\frac1\theta x^{(1-\theta)/\theta}$ on $0<x<1$, $\theta>0$. Derive $\hat\theta_{\text{MLE}}$. > > > [!SUCCESS]- Reference solution > > $$ > > \begin{aligned} > > P(\mathbf{x}\mid\theta)&=\prod_{i=1}^n\frac1\theta x_i^{(1-\theta)/\theta}=\frac{1}{\theta^n}\prod_{i=1}^n x_i^{(1-\theta)/\theta}\\ > > L(\mathbf{x}\mid\theta)&=n\log\theta-\frac{1-\theta}{\theta}\sum_{i=1}^n\log x_i=n\log\theta-\frac{1}{\theta}\sum_i\log x_i+\sum_i\log x_i\\ > > \frac{dL}{d\theta}&=\frac{n}{\theta}+\frac{1}{\theta^2}\sum_i\log x_i=0\;\Rightarrow\;n\theta+\sum_i\log x_i=0\;\Rightarrow\;\hat\theta=-\frac{\sum_{i=1}^n\log x_i}{n} > > \end{aligned} > > $$ > > - **Key move:** $\log\left(\prod x_i^{c}\right)=c\sum\log x_i$, then multiply by $\theta^2$ to clear denominators; $\hat\theta>0$ because $\log x_i<0$ on $0<x<1$. > [!QUESTION]- Practice 3: seed germination with $f_X(x)=\lambda x^{\lambda-1}$ on $0<x<1$ (else $0$), $\lambda>0$. Derive $\hat\lambda_{\text{MLE}}$ and contrast with Practice 2. > > > [!SUCCESS]- Reference solution > > $$ > > \begin{aligned} > > P(\mathbf{x}\mid\lambda)&=\prod_{i=1}^n\lambda x_i^{\lambda-1}=\lambda^n\left(\prod_{i=1}^n x_i\right)^{\lambda-1}\\ > > L(\mathbf{x}\mid\lambda)&=-n\log\lambda-(\lambda-1)\sum_{i=1}^n\log x_i\\ > > \frac{dL}{d\lambda}&=-\frac{n}{\lambda}-\sum_i\log x_i=0\;\Rightarrow\;\frac{n}{\lambda}=-\sum_i\log x_i\;\Rightarrow\;\hat\lambda=-\frac{n}{\sum_{i=1}^n\log x_i} > > \end{aligned} > > $$ > > - **Key move:** the exponent here is $\lambda-1$ (linear in the parameter) versus $(1-\theta)/\theta$ (a **reciprocal** in the parameter) ➔ same data, **reciprocal** estimators: $\hat\lambda=n/(-\sum\log x_i)$ against $\hat\theta=(-\sum\log x_i)/n$. ## ⚠️ Common Mistakes - 💡 **Maximising the NLL** ➔ $L$ carries the minus sign already; maximise $p(\mathbf{y}\mid\theta)$ **or** minimise $L(\mathbf{y}\mid\theta)$, never maximise $L$. - 💡 **Dropping the $\theta$-free terms too early — or too late** ➔ $\sum\log y_i!$ (Poisson) and $\frac{n}{2}\log 2\pi$ (Gaussian) vanish on differentiation, but they belong in $L$ if the question asks for the NLL *value*. - 💡 **Differentiating in $\sigma$ before plugging in $\hat\mu$** ➔ leaves two unknowns coupled; substitute $\hat\mu$ first, then the $\sigma$ equation solves in one line. - 💡 **Assuming the MLE is always the sample mean** ➔ true for Gaussian $\mu$ and Poisson $\lambda$, false for $\mathrm{Exp}(\beta)$ ($1/\bar y$) and for the power families above. - 💡 **Forgetting the ML variance divides by $n$** ➔ $\hat\sigma^2_{ML}=\frac1n\sum(y_i-\bar y)^2$; the $n-1$ version is a *different*, unbiased estimator — see [[Estimator Quality (Bias, Variance, MSE)]]. - 💡 **Taking a boundary estimate at face value** ➔ $m=n$ gives $\hat\theta=1$ and $m=0$ gives $\hat\theta=0$, **ruling out** the unseen outcome entirely in every future prediction; ML is **overconfident on small samples** and at $n=1$ this happens always. ## 🧠 Active Recall > [!FAQ]- Why is minimum squared error abandoned in favour of maximum likelihood, given both return $\bar y$ for the Gaussian mean? > > > [!SUCCESS]- Answer > > - **Short answer:** SSE only scores **closeness of a centre** — it offers no goodness-of-fit measure for a spread parameter like $\sigma$, whereas ML scores the **whole model** and so estimates every parameter of any family. > > - **Why:** **Generality** ➔ ML's criterion $p(\mathbf{y}\mid\theta)$ is defined for any $\theta\in\Theta$ of any distribution, giving simultaneous equations $\partial L/\partial\mu=0,\ \partial L/\partial\sigma=0$; the agreement on $\hat\mu=\bar y$ is a **coincidence of the Gaussian's quadratic exponent**, not equivalence of methods. > [!FAQ]- You toss a coin twice and see two heads. What does ML report for $\theta$, why is that a problem, and what does it say about ML generally? > > > [!SUCCESS]- Answer > > - **Short answer:** $\hat\theta_{ML}=m/n=2/2=1$ ➔ the plug-in model assigns $P(\text{tail})=0$, declaring a tail **impossible** on all future tosses. No one would accept that conclusion from two tosses. > > - **Why:** **ML optimises fit to the observed sample, with no allowance for what was not observed** ➔ the boundary estimates $\hat\theta\in\{0,1\}$ are attained whenever $m\in\{0,n\}$, which is likely for small $n$ and certain at $n=1$; the estimator is therefore **overconfident**, and the fix is either more data or a prior that keeps $\hat\theta$ off the boundary. > > - **Hint:** the same over-confidence appears continuously as $\hat\sigma^2_{ML}$ **understating spread** — see [[Plug-in Prediction and Held-Out Evaluation]], where the too-narrow density mispredicts held-out tail probabilities. > [!FAQ]- Why take logs at all, and why does it not change the answer? > > > [!SUCCESS]- Answer > > - **Short answer:** $\log$ turns $\prod_i p(y_i\mid\theta)$ into $\sum_i\log p(y_i\mid\theta)$ — differentiable term by term and numerically stable — and because $\log$ is **strictly increasing**, $\arg\max_\theta p=\arg\max_\theta\log p=\arg\min_\theta\{-\log p\}$. > > - **Why:** **Monotone reparameterisation of the objective** ➔ a strictly increasing transform preserves the *location* of the extremum while changing its value; without it the product of $n$ densities underflows and the chain rule compounds across $n$ factors.