Day 11. Maximum Likelihood Estimation
Choosing the parameter that makes the observed data most probable, and measuring its precision from the curvature.
- ●Write the likelihood and log-likelihood for Bernoulli, Poisson, normal and exponential data.
- ●Derive MLEs from the first-order condition and check the second-order condition.
- ●Use Fisher information to get standard errors, and the invariance property for transformations.
- ●Run a likelihood-ratio test and connect OLS and logit to maximum likelihood.
Theory
Likelihood
For iid data from a density or pmf , the likelihood is the joint probability of the data, read as a function of :
Probability fixes and varies the data; likelihood fixes the data and varies . Logs turn products into sums and do not move the maximiser.
The maximum likelihood estimator
maximises . Usually you solve the score equation and check .
Precision from curvature
The Fisher information per observation is . Under regularity conditions,
A sharply peaked log-likelihood (large curvature) means a precise estimate. In practice, .
Two more tools
- Invariance: the MLE of is .
- Likelihood-ratio test: under ; reject at 5% if .
Causal link. Logit and probit propensity-score models, duration models and many structural models are estimated by maximum likelihood. On Day 13 you will see that the posterior mode with a flat prior is the MLE.
Part 1 · Warm-up
Exercise 1 · Probability or likelihood?
Which is a probability and which a likelihood: (a) "if , the chance of 3 heads in 4 tosses is 0.25"; (b) "given 3 heads in 4 tosses, fits better than "?
Show solution
Step 1. (a) is a probability: the parameter is fixed and we ask about data.
Step 2. (b) compares likelihoods: the data are fixed and we compare parameter values.
Step 3. Likelihoods need not sum to 1 over .
Exercise 2 · A Bernoulli likelihood
Data: 1, 1, 0, 1. Write and evaluate it at and .
Show solution
Step 1. .
Step 2. and .
Step 3. The data are more probable under .
Exercise 3 · Log-likelihood
Write for the same data.
Show solution
.
Exercise 4 · Maximise
Find the MLE for these data.
Show solution
. And , so it is a maximum.
Exercise 5 · Exponential durations
Five unemployment spells last 2, 3, 4, 5 and 6 months. With , find .
Show solution
, so and per month (mean spell 4 months).
Part 2 · Proofs
Exercise 6 · Bernoulli MLE in general
With successes in trials, show .
Show solution
Step 1. .
Step 2. Setting gives , so .
Step 3. The second derivative is negative everywhere, so this is the global maximum.
Exercise 7 · Poisson MLE
Show that the MLE of for iid Poisson data is .
Show solution
, so .
Exercise 8 · Normal mean
For iid, show .
Show solution
Step 1. .
Step 2. Maximising over means minimising , a least-squares problem: .
Exercise 9 · Normal variance
Show . Is it unbiased?
Show solution
Step 1. .
Step 2. This is the plug-in variance from Day 8: biased (by ) but consistent.
Step 3. MLEs are often biased in small samples.
Exercise 10 · Fisher information for a proportion
Show for one Bernoulli observation, so .
Show solution
, so . Taking expectations with :
So , the familiar variance of a proportion.
Part 3 · Applied
Exercise 11 · A conversion rate
18 of 30 households adopt a new technology. Find and its standard error.
Show solution
Step 1. Bernoulli MLE (Exercise 6): .
Step 2. Fisher information gives .
Step 3. .
Answer: 60% adoption, SE ≈ 0.089. Slide and in the Lab's likelihood explorer to see the curve sharpen as grows.
Exercise 12 · Invariance
Using Exercise 11, find the MLE of the odds and of the log-odds.
Show solution
Step 1. Invariance: the MLE of a function of is that function of .
Step 2. Odds: (three adopters for every two non-adopters).
Step 3. Log-odds: , the scale on which a logit model works.
Answer: odds 1.5 and log-odds 0.405. Their standard errors come from the delta method (Day 12).
Exercise 13 · A likelihood-ratio test
Test for the data in Exercise 11.
Show solution
Step 1. Log-likelihood at the MLE:
Step 2. Log-likelihood under :
Step 3. .
Step 4. Compare with the 5% critical value 3.84: ().
Answer: do not reject . The Wald test agrees: .
Exercise 14 · OLS is MLE in a wage equation
A labour economist models log wages as with iid. Show that the maximum-likelihood estimates of are the OLS estimates.
Show solution
Step 1. Each is , so the log-likelihood is
Step 2. The s appear only in the sum of squares, with a negative sign.
Step 3. For any , maximising over the s is therefore the same as minimising the sum of squared residuals: the definition of OLS.
Answer: under normal errors, MLE and OLS coincide. (Without normality OLS is still a sensible estimator, Day 29.)
Exercise 15 · The propensity-score score equation
An evaluator models the probability that worker joins a training programme with a logit, , , where holds age, education and past earnings. Show that the score equation is , and interpret the equation for the intercept.
Show solution
Step 1. Log-likelihood: with .
Step 2. Useful fact: , so .
Step 3. Chain rule:
Step 4. Set it to zero. The intercept's entry of is 1, giving .
Answer: the fitted propensities average exactly to the share of workers trained. This logit is the standard propensity-score model of Phase 3.
Verify in Python
import numpy as np
from scipy import optimize, stats
k, n = 18, 30
loglik = lambda p: k * np.log(p) + (n - k) * np.log(1 - p)
res = optimize.minimize_scalar(lambda p: -loglik(p), bounds=(1e-6, 1 - 1e-6), method="bounded")
p_hat = res.x
h = 1e-5
curv = (loglik(p_hat + h) - 2 * loglik(p_hat) + loglik(p_hat - h)) / h**2
print(f"p_hat = {p_hat:.4f}, SE from curvature = {1/np.sqrt(-curv):.4f}, "
f"formula = {np.sqrt(p_hat*(1-p_hat)/n):.4f}")
LR = 2 * (loglik(0.6) - loglik(0.5))
print(f"LR = {LR:.3f}, p-value = {stats.chi2.sf(LR, 1):.3f}")
# Logit by maximum likelihood on simulated data
rng = np.random.default_rng(11)
x = rng.normal(size=20_000); X = np.column_stack([np.ones_like(x), x])
T = rng.random(20_000) < 1 / (1 + np.exp(-(-0.5 + 1.0 * x)))
nll = lambda b: -np.sum(T * (X @ b) - np.log1p(np.exp(X @ b)))
b_hat = optimize.minimize(nll, np.zeros(2)).x
print("logit estimates:", b_hat.round(3), "(truth -0.5, 1.0)")
print("score at optimum:", (X.T @ (T - 1 / (1 + np.exp(-X @ b_hat)))).round(3))
Key takeaways
- The MLE picks the parameter under which the observed data are most probable.
- Curvature of the log-likelihood (Fisher information) gives the standard error.
- OLS with normal errors and the logit propensity model are both maximum-likelihood estimators.
Simulation Lab: Log-Likelihood Explorer
Open full screen →Move the parameter along a Bernoulli log-likelihood; see the peak, its curvature and the LR test.
The log-likelihood peaks at p̂ = S/N. The dashed parabola is the quadratic approximation whose curvature (Fisher information) gives the SE. The green band is the 95% likelihood-ratio interval: all p within 1.92 log-points of the peak.