11 Estimation and maximum likelihood
Imagine monitoring a system whose job arrivals follow a Poisson model, but whose arrival rate is unknown. Probability would ask how likely a count of twelve is for a given rate. Inference reverses the problem: given observed counts, what rate is supported by the observations, and how uncertain is that estimate?
11.1 Models, parameters and estimators
A parametric statistical model is a family \(\{P_\theta:\theta\in\Theta\}\) of probability laws indexed by an unknown parameter. The model is identifiable if \(P_{\theta_1}=P_{\theta_2}\) implies \(\theta_1=\theta_2\). Without identifiability, distinct parameter values imply exactly the same observable distribution, so no amount of data can distinguish them.
An estimator \(\widehat\theta=T(X_1,\ldots,X_n)\) is a statistic used to infer \(\theta\). Its value after observing data is an estimate. We evaluate an estimator across repeated samples from \(P_\theta\):
\[ \begin{aligned} \operatorname{Bias}_\theta(T)&=E_\theta[T]-\theta,\\ \operatorname{MSE}_\theta(T)&=E_\theta[(T-\theta)^2]\\ &=\operatorname{Var}_\theta(T)+\operatorname{Bias}_\theta(T)^2. \end{aligned} \]
To derive the final identity, write \(T-\theta=(T-E_\theta T)+(E_\theta T-\theta)\), expand the square, and note the expected cross term is zero. An estimator is consistent if \(T_n\xrightarrow P\theta\) under each relevant true \(\theta\). Unbiasedness is a finite-sample property; consistency is asymptotic. Neither implies the other without additional conditions.
The loss used here is squared error. Another decision problem may prefer absolute error or a strongly asymmetric loss. The best estimator depends on both the model and the objective.
11.2 The method of moments
For a model with \(k\) parameters, choose \(k\) population moment equations and replace the expectations by sample averages. Solve for the parameters. For example, if \(X_i\sim\operatorname{Gamma}(\alpha,\lambda)\), then \(m=E[X]=\alpha/\lambda\) and \(v=\operatorname{Var}(X)=\alpha/\lambda^2\). Solving gives
\[ \widehat\alpha_{\rm MOM}=\frac{\bar X^2}{\widehat v},\qquad \widehat\lambda_{\rm MOM}=\frac{\bar X}{\widehat v},\quad \widehat v=\frac1n\sum_i(X_i-\bar X)^2. \]
When the model has positive variance, the LLN for the first two raw moments and continuity of these formulas imply consistency. Moment estimates can be useful starting points for numerical optimization. The method depends on which moments are matched, and sample moments may occasionally lie outside the model’s admissible range.
11.3 The likelihood function
Given independent observations \(x_1,\dots,x_n\) from a PMF or PDF \(f_\theta\), the likelihood function is
\[ L(\theta;x)=\prod_{i=1}^n f_\theta(x_i). \]
The data are fixed and \(\theta\) varies. For continuous data it is a joint density evaluated at the observations, not the probability of observing precisely those values. It need not integrate to one over \(\Theta\).
The maximum likelihood estimator (MLE) maximizes the likelihood. Since \(\log\) is strictly increasing, maximizing the log-likelihood is equivalent:
\[ \widehat\theta_{\rm MLE}\in\arg\max_{\theta\in\Theta}\ell(\theta), \qquad \ell(\theta)=\sum_i\log f_\theta(x_i). \]
At a differentiable interior maximum the score \(U(\theta)=\ell'(\theta)\) is zero; a negative second derivative confirms a strict local maximum. A global maximum may be on a boundary or at a nondifferentiable point. If the log-likelihood is concave, any interior stationary point is global.
11.3.1 Bernoulli and Poisson examples
For Bernoulli observations of count \(s=\sum_i x_i\), the log-likelihood on \(0<p<1\) is
\[ \ell(p)=s\log p+(n-s)\log(1-p). \]
When \(0<s<n\), its derivative \(s/p-(n-s)/(1-p)\) vanishes exactly at \(p=s/n\). The second derivative is \(-s/p^2-(n-s)/(1-p)^2<0\), proving maximality. When \(s=0\) or \(s=n\), monotonicity gives the boundary MLE 0 or 1. Thus the MLE is \(\bar X\) including the endpoints.
For Poisson counts with rate \(\lambda>0\),
\[ \ell(\lambda)=-n\lambda+s\log\lambda-\sum_i\log(x_i!). \]
If \(s>0\), the derivative is \(-n+s/\lambda\) and the maximum is \(\widehat\lambda=\bar X\). If \(s=0\) the likelihood decreases with \(\lambda\), so its supremum is approached as \(\lambda\downarrow0\) (attained at zero if the degenerate law is included).
11.3.2 Exponential rates and finite-sample bias
For exponential observations of rate \(\lambda\),
\[ \ell(\lambda)=n\log\lambda-\lambda T,\qquad T=\sum_i x_i. \]
The derivative gives \(\widehat\lambda=n/T\) and \(\ell''=-n/\lambda^2<0\). The sum \(T\sim\operatorname{Gamma}(n,\lambda)\). For \(n>1\),
\[ E[T^{-1}]=\frac{\lambda^n}{\Gamma(n)}\int_0^\infty t^{n-2}e^{-\lambda t}dt =\frac{\lambda}{n-1}. \]
Hence \(E[\widehat\lambda]=n\lambda/(n-1)>\lambda\). The estimator \((n-1)/T\) is unbiased. Nevertheless, the MLE is consistent because \(T/n\xrightarrow P1/\lambda\).
11.3.3 Normal mean and variance
For iid normal observations with unknown \(\mu\) and \(v=\sigma^2>0\),
\[ \ell(\mu,v)=-\frac n2\log(2\pi v)-\frac{1}{2v}\sum_i(x_i-\mu)^2. \]
For fixed \(v\), the unique maximizer in \(\mu\) is \(\bar x\) by the residual-sum identity. Substituting it and differentiating with respect to \(v\) gives
\[ \widehat\mu=\bar X,\qquad \widehat v=\frac1n\sum_i(X_i-\bar X)^2. \]
With nonzero residual sum of squares, the profile log-likelihood increases until this positive variance then decreases, proving the maximum. If every observation equals the same value, the likelihood diverges as \(v\downarrow0\) at \(\mu=\bar x\); a positive-variance MLE does not exist in this exceptional case. For \(n\ge2\) and a nondegenerate normal model the exceptional event has probability zero.
11.3.4 A support-dependent example
If \(X_i\sim\operatorname{Uniform}(0,\theta)\) with \(\theta>0\), the likelihood is \(\theta^{-n}\mathbf1_{\{\theta\ge X_{(n)}\}}\) (choose the endpoint-inclusive density version). For feasible \(\theta\) it decreases, so \(\widehat\theta=X_{(n)}\). The derivative does not vanish at the maximum.
Since \(P(X_{(n)}\le x)=(x/\theta)^n\) for \(0\le x\le\theta\), integration gives \(E[X_{(n)}]=n\theta/(n+1)\). Multiplying the sample maximum by \((n+1)/n\) removes this bias. The usual regular MLE asymptotic theory will not apply unchanged because the support depends on the unknown parameter.
11.4 Sufficiency
A statistic \(T(X)\) is sufficient for \(\theta\) if the conditional distribution of the data given \(T\) does not depend on \(\theta\). In a dominated parametric model, the factorization theorem says this is equivalent (up to appropriate null sets) to
\[ f_\theta(x)=g_\theta(T(x))h(x) \]
with \(h\) independent of \(\theta\). To see the discrete direction, condition on \(T=t\): the factor \(g_\theta(t)\) cancels between numerator and denominator,
\[ P_\theta(X=x\mid T=t) =\frac{h(x)}{\sum_{y:T(y)=t}h(y)} \]
for feasible \(x\) and \(t\). The general theorem extends the argument to densities and conditional measures. In the Poisson model the likelihood factors into \(e^{-n\lambda}\lambda^{\sum x_i}\) and \(\prod_i1/x_i!\), proving the total count is sufficient. Once the total is known, the distribution of how counts were allocated to observations contains no extra information about the shared rate.
11.5 Fisher information and the Cramér–Rao bound
Consider a differentiable one-parameter model with parameter-independent support, sufficiently integrable derivatives to differentiate under the integral, and finite positive information. For one observation define the score \(u_\theta(X)=\partial_\theta\log f_\theta(X)\) and information
\[ I(\theta)=E_\theta[u_\theta(X)^2]. \]
Since \(\partial_\theta f_\theta=f_\theta u_\theta\), differentiating \(\int f_\theta=1\) gives \(E_\theta u_\theta=0\). Under twice-differentiability and valid interchange again, differentiating \(E_\theta u_\theta=0\) yields \(I(\theta)=-E_\theta[\partial_\theta^2\log f_\theta(X)]\). For iid observations, independent mean-zero scores add, and total information is \(nI(\theta)\).
If \(T\) is unbiased with finite variance and the differentiating-expectation identity is justified,
\[ 1=\partial_\theta E_\theta[T] =E_\theta[TU(\theta)] =\operatorname{Cov}_\theta(T,U). \]
By Cauchy–Schwarz,
\[ 1\le\operatorname{Var}_\theta(T)\operatorname{Var}_\theta(U) =\operatorname{Var}_\theta(T)n I(\theta). \]
This proves the Cramér–Rao lower bound \(\operatorname{Var}(T)\ge1/(nI(\theta))\). For Bernoulli data \(I(p)=1/[p(1-p)]\) at interior \(p\). The sample proportion’s variance is exactly \(p(1-p)/n\), so it attains the bound.
11.5.1 Large-sample likelihood theory
Under additional regularity (including identifiability, an interior true parameter, smoothness, suitable LLNs for derivatives, and a consistent interior MLE), the MLE satisfies
\[ \sqrt n(\widehat\theta-\theta_0)\xrightarrow d N(0,I(\theta_0)^{-1}). \]
The score equation and a mean-value expansion give
\[ 0=U_n(\theta_0)+\ell_n''(\theta_n^*)(\widehat\theta-\theta_0). \]
By a CLT, \(U_n(\theta_0)/\sqrt n\xrightarrow d N(0,I(\theta_0))\). Under the derivative LLN, \(\ell_n''(\theta_n^*)/n\xrightarrow P-I(\theta_0)\). Divide the equation by \(\sqrt n\) and apply Slutsky. This is the central argument; consistency and the derivative LLN themselves require the regular conditions just stated. Boundary and support-dependent examples warn against treating the asymptotic normal formula as universal.
11.6 Practice problems
Work in your browser with Google Colab, or download the notebooks for Jupyter.
Practice notebook
Worked solutions
11.6.1 Exercise 1: Estimate a count rate
Observe counts \((2,4,3,0,6)\) from independent Poisson windows. Derive the MLE and its variance in terms of the true rate. Estimate its standard error.
\(s=15,n=5\). The derivative \(-5+15/\lambda\) vanishes at \(\widehat\lambda=3\); the second derivative is negative. The estimator is unbiased with variance \(\lambda/5\). A plug-in standard error is \(\sqrt{3/5}\approx0.775\).
11.6.2 Exercise 2: Information about a normal mean
For \(X\sim N(\mu,\sigma^2)\) with known positive \(\sigma^2\), derive \(I(\mu)\). Show the sample mean attains the Cramér–Rao bound.
\(u_\mu(X)=(X-\mu)/\sigma^2\). Its mean is zero, and its second moment is \(\sigma^2/\sigma^4=1/\sigma^2\). So the bound is \(\sigma^2/n\). The unbiased sample mean has exactly this variance.
11.6.3 Exercise 3: Uniform endpoints
Show that the unbiased endpoint estimator \((n+1)X_{(n)}/n\) from the uniform \((0,\theta)\) model is consistent, and compute its variance.
Let \(M=X_{(n)}\). For \(0<\epsilon<\theta\), \(P(M<\theta-\epsilon)=(1-\epsilon/\theta)^n\to0\), while \(M\le\theta\) always. Thus \(M\to\theta\) in probability and \((n+1)M/n\) is consistent. Also \(E[M^k]=n\theta^k/(n+k)\) by integration. Consequently \[ \operatorname{Var}\left(\frac{n+1}{n}M\right) =\frac{(n+1)^2}{n^2}\frac{n\theta^2}{n+2}-\theta^2 =\frac{\theta^2}{n(n+2)}. \] The usual information-bound argument fails because the support changes with \(\theta\).
11.6.4 Exercise 4: See bias and MSE (Python)
Simulate 40,000 exponential samples of size four with rate two. Compare \(n/T\) with \((n-1)/T\) on empirical mean, variance and MSE. Which estimator has smaller bias? Which has smaller MSE here?
import numpy as np
rng = np.random.default_rng(1101)
n, rate = 4, 2
t = rng.exponential(1/rate, (40_000, n)).sum(axis=1)
for label, est in [("MLE", n/t), ("Unbiased", (n-1)/t)]:
print(label, "bias", est.mean()-rate, "variance", est.var(),
"MSE", np.mean((est-rate)**2))The unbiased estimator has expected bias zero. For \(n>2\), \(E[T^{-2}]=\lambda^2/[(n-1)(n-2)]\). Here the unbiased estimator has MSE \(\lambda^2/(n-2)=2\); the MLE has MSE \(4\) at \(n=4,\lambda=2\). Monte Carlo approximates these values, with potentially substantial tail variation.
11.6.5 Exercise 5: Numerically maximize a likelihood (Python)
Generate 100 Bernoulli observations with probability .35. Maximize the log-likelihood numerically on \((0,1)\) and compare with the sample proportion. Plot the likelihood relative to its maximum.
import numpy as np
from scipy.optimize import minimize_scalar
import matplotlib.pyplot as plt
rng = np.random.default_rng(1102)
x = rng.binomial(1, .35, 100)
s, n = x.sum(), x.size
def loglik(p):
return s*np.log(p)+(n-s)*np.log1p(-p)
res = minimize_scalar(lambda p: -loglik(p),
bounds=(1e-8,1-1e-8), method="bounded")
g = np.linspace(.001,.999,400)
print("Numeric:", res.x, "Analytic:", x.mean())
plt.plot(g, np.exp(loglik(g)-loglik(res.x)))
plt.axvline(res.x, color="black", linestyle="--")
plt.xlabel("Candidate p")
plt.ylabel("Relative likelihood")
plt.show()
assert res.success and abs(res.x-x.mean()) < 1e-5Subtracting the maximal log-likelihood before exponentiating keeps the relative likelihood bounded by one and avoids underflow from a large product.
11.6.6 Exercise 6: Compare method-of-moments and MLE (Python)
Generate 500 gamma observations with shape 3 and rate 2. Compute the method-of-moments estimates and fit the gamma model using SciPy with location fixed at zero. Compare with the true values and evaluate both fitted CDFs on the data.
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
rng = np.random.default_rng(1103)
x = rng.gamma(3, 1/2, 500)
m, v = x.mean(), x.var()
a_mom, r_mom = m*m/v, m/v
a_mle, loc, scale_mle = stats.gamma.fit(x, floc=0)
r_mle = 1/scale_mle
print("MOM:", a_mom, r_mom, "MLE:", a_mle, r_mle)
g = np.sort(x)
plt.step(g, np.arange(1, x.size+1)/x.size, label="Empirical")
plt.plot(g, stats.gamma.cdf(g,a_mom,scale=1/r_mom), label="MOM")
plt.plot(g, stats.gamma.cdf(g,a_mle,scale=1/r_mle), "--", label="MLE")
plt.legend()
plt.show()Both estimates fluctuate with the sample. Fixing location is essential because our model has support starting at zero. SciPy uses scale rather than rate, so invert the fitted scale.