Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Tuesday’s solver becomes an estimator once a likelihood is wrapped around it: for every parameter vector, solve the model and evaluate the probability of the data. This class is maximum likelihood for dynamic models, and the nested fixed point (NFXP) algorithm of Rust (1987) that makes it fast.

Maximum likelihood estimation

The maximum likelihood estimator is applicable when the model yields a probability distribution for the observable data. Let L(z,θ)L(z,\theta) denote the distribution (pdf) of the observables zz implied by the model with parameter vector θ\theta, and let Zn=(z1,…,zn)Z_n = (z_1,\dots,z_n) denote the data, consisting of nn independent observations, a random sample. MLE and MSM are the two main estimation methods for dynamic economic models, and the method of simulated moments comes later in the course.

Likelihood function

If L(z,θ)L(z,\theta) is a discrete distribution then L(z,θ)L(z,\theta) computed at the data point gives the probability of observing that data point exactly. If L(z,θ)L(z,\theta) is a continuous distribution then L(z,θ)L(z,\theta) computed at the data point is analogous to the probability of observing it. Either way, independence across observations makes the joint probability of the sample a product,

Ln(θ)=L(Zn,θ)=∏i=1nL(zi,θ)\mathcal{L}_n(\theta) = L(Z_n,\theta) = \prod_{i=1}^n L(z_i,\theta)

which is the likelihood function: the data are fixed, and it is a function of the parameters.

The log is there for the numerics as much as for the algebra: a product of a few thousand probabilities underflows to zero long before the sample is exhausted, and a sum of their logs does not. Never take the log of a probability, from Class 6, applies to every term of ℓn(θ)\ell_n(\theta).

Asymptotic properties of MLE

Under regularity conditions the MLE has four properties that make it the default estimator whenever a likelihood is available (Newey & McFadden (1994), Theorems 2.5, 3.3 and 5.1):

  1. Consistency: θ^MLE→pθ0\hat{\theta}_{MLE} \xrightarrow{p} \theta_0

  2. Asymptotic normality: n(θ^MLE−θ0)→dN(0,I(θ0)−1)\sqrt{n} ( \hat{\theta}_{MLE} - \theta_0 ) \xrightarrow{d} N(0,\mathcal{I}(\theta_0)^{-1})

  3. Asymptotic efficiency: I(θ0)−1\mathcal{I}(\theta_0)^{-1} is the smallest asymptotic variance attainable in the class of GMM estimators, which includes method of moments and least squares — the large-sample counterpart of the Cramér–Rao bound

  4. Functional invariance: the MLE of γ0=g(θ0)\gamma_0 = g(\theta_0) is given by g(θ^MLE)g(\hat{\theta}_{MLE}) for any function g(⋅)g(\cdot); continuous differentiability of gg is needed only for the delta-method standard errors of γ^\hat{\gamma}

The price is the regularity conditions — identification, a compact parameter space, continuity and a dominance condition on ℓ(z,θ)\ell(z,\theta) for consistency; an interior θ0\theta_0, twice differentiability and a nonsingular I(θ0)\mathcal{I}(\theta_0) for normality — and the assumption that the model is correctly specified: a misspecified likelihood still produces an estimate, but the properties above no longer describe it.

Asymptotic variance of the MLE

The asymptotic normality result can be read as a statement about the standardized estimator,

n(θ^MLE−θ0)→dN(0,I(θ0)−1)⇔In(θ0)(θ^MLE−θ0)→dN(0,1)\sqrt{n} ( \hat{\theta}_{MLE} - \theta_0 ) \xrightarrow{d} N(0,\mathcal{I}(\theta_0)^{-1}) \Leftrightarrow \sqrt{\mathcal{I}_n(\theta_0)} ( \hat{\theta}_{MLE} - \theta_0 ) \xrightarrow{d} N(0,1)

where, for a scalar parameter, the variance is given by the inverse of the Fisher information, computed from the pdf L(z,θ0)L(z,\theta_0) as the expected curvature of the log-likelihood, or equivalently as the expected squared score (under regularity conditions):

I(θ0)=−E[∂2∂θ∂θℓ(z,θ0)]=E[(∂∂θℓ(z,θ0))2]\mathcal{I}(\theta_0) = - \mathbb{E}\left[ \frac{\partial^2}{\partial\theta \partial\theta} \ell(z,\theta_0) \right] = \mathbb{E}\left[ \left( \frac{\partial}{\partial\theta} \ell(z,\theta_0) \right)^2 \right]

The Fisher information matrix can be computed also from the log-likelihood function ℓn(θ0)\ell_n(\theta_0) of nn i.i.d. random variables in place of the data ZnZ_n, and it scales with the sample size:

In(θ0)=−E[∂2∂θ∂θℓn(θ0)]=E[(∂∂θℓn(θ0))2]=nI(θ0)\mathcal{I}_n(\theta_0) = - \mathbb{E}\left[ \frac{\partial^2}{\partial\theta \partial\theta} \ell_n(\theta_0) \right] = \mathbb{E}\left[ \left( \frac{\partial}{\partial\theta} \ell_n(\theta_0) \right)^2 \right] = n \mathcal{I}(\theta_0)

Let individual log-likelihoods and scores be

ℓi(θ)=ℓ(zi,θ)=log⁡L(zi,θ),si(θ)=∂ℓi(θ)∂θ.\ell_i(\theta)=\ell(z_i,\theta)=\log L(z_i,\theta), \qquad s_i(\theta)=\frac{\partial \ell_i(\theta)}{\partial\theta}.

Fisher information can be consistently estimated from a sample of nn observations by plugging in the MLE estimate θ^\hat\theta in two different ways:

J^n,OPG=1n∑i=1nsi(θ^)si(θ^)⊤\hat{\mathcal{J}}_{n,\mathrm{OPG}} = \frac{1}{n} \sum_{i=1}^n s_i(\hat\theta)s_i(\hat\theta)^\top
J^n,H=−1n∑i=1n∂2ℓi(θ^)∂θ∂θ⊤=−1n∇θ2ℓn(θ^).\hat{\mathcal{J}}_{n,\mathrm{H}} = -\frac{1}{n} \sum_{i=1}^n \frac{\partial^2\ell_i(\hat\theta)} {\partial\theta\partial\theta^\top} = -\frac{1}{n} \nabla_\theta^2\ell_n(\hat\theta).

Newey & McFadden (1994), Theorem 4.4, list mild regularity condition under which both of these estimators are consistent for the true Fisher information I(θ0)\mathcal{I}(\theta_0), leading to

J^n(θ^)(θ^−θ0)→dN(0,1)⇒θ^≈N(θ0,J^n(θ^)−1)\sqrt{\hat{\mathcal{J}}_n(\hat{\theta})} ( \hat{\theta} - \theta_0 ) \xrightarrow{d} N(0,1) \Rightarrow \hat{\theta} \approx N(\theta_0, \hat{\mathcal{J}}_n(\hat{\theta})^{-1})

so the standard errors of the estimates are the square roots of the diagonal of the inverse of the negative Hessian of the log-likelihood at the optimum. Every optimizer that uses a Hessian, or an approximation to it, has the standard errors for free.

Outer product of gradients

Consider a vector random variable X~=(X~1,…,X~K)T\tilde{X} = (\tilde{X}_1,\dots,\tilde{X}_K)^{T}, a column vector K×1K \times 1, with expectation given by the K×1K \times 1 vector EX~\mathbb{E}\tilde{X}. The K×KK \times K variance-covariance matrix Σ\Sigma of X~\tilde{X} is given by the expectation of the outer product ⊗\otimes,

Σ=E{(X~−EX~)⊗(X~−EX~)T}\Sigma = \mathbb{E} \left\{ \big( \tilde{X}-\mathbb{E}\tilde{X} \big) \otimes \big( \tilde{X}-\mathbb{E}\tilde{X} \big)^{T} \right\}

The variances of the elements of X~\tilde{X} are on the main diagonal of Σ\Sigma, whereas the off-diagonal elements contain the covariances cov(X~i,X~j)cov(\tilde{X}_i,\tilde{X}_j) for all i≠ji \ne j.

Information matrix equality

Then the information matrix equality (Newey & McFadden (1994), Theorem 3.3)

In(θ0)=−E H(ℓn(θ0))=E∑i=1n∇ℓ(zi,θ0)⊗∇ℓ(zi,θ0)T\mathcal{I}_n(\theta_0) = - \mathbb{E}\, H(\ell_n(\theta_0)) = \mathbb{E} \sum_{i=1}^n \nabla\ell(z_i, \theta_0) \otimes \nabla\ell(z_i, \theta_0)^{T}

has the sample analogue

J^n(θ0)=−H(ℓn(θ0))≈∑i=1n∇ℓ(zi,θ0)⊗∇ℓ(zi,θ0)T=∇ℓ(Zn,θ0) ∇ℓ(Zn,θ0)T\begin{aligned} \hat{\mathcal{J}}_n(\theta_0) = - H(\ell_n(\theta_0)) &\approx \sum_{i=1}^n \nabla\ell(z_i, \theta_0) \otimes \nabla\ell(z_i, \theta_0)^{T} \\ &= \nabla\ell(Z_n, \theta_0) \, \nabla\ell(Z_n, \theta_0)^{T} \end{aligned}

The right hand side needs first derivatives only, one score vector per observation. That is what makes it useful inside an optimizer.

Berndt–Hall–Hall–Hausman (BHHH) algorithm

The information matrix equality gives an approximation of the Hessian of the log-likelihood function that can be used in a quasi-Newton optimization method,

H(ℓn(θ))≈−∇ℓ(Zn,θ) ∇ℓ(Zn,θ)TH(\ell_n(\theta)) \approx - \nabla\ell(Z_n, \theta) \, \nabla\ell(Z_n, \theta)^{T}

which is the BHHH algorithm of Berndt et al. (1974), introduced with the other quasi-Newton methods in Class 5. The outer product of gradients is a positive semi-definite matrix for every θ\theta, so even if the approximation is not accurate it never points the Newton iteration in the wrong direction. A search for an appropriate step size in the direction found with the approximated Hessian is part of the algorithm to ensure global convergence.

Where it breaks: the equality holds at θ0\theta_0, in expectation, for a correctly specified model. Far from the optimum, in small samples, or under misspecification the outer product is a poor Hessian, and the standard errors it implies are wrong even when the point estimate is fine. The sandwich estimator that combines both sides of the equality, J^n(θ^)−1 ∇ℓ(Zn,θ^)∇ℓ(Zn,θ^)T J^n(θ^)−1\hat{\mathcal{J}}_n(\hat\theta)^{-1} \, \nabla\ell(Z_n, \hat\theta) \nabla\ell(Z_n, \hat\theta)^{T} \, \hat{\mathcal{J}}_n(\hat\theta)^{-1}, is the robust alternative (Newey & McFadden (1994), Section 4.2).

  • Why maximize the log-likelihood rather than the likelihood in code?

  • Which of the four asymptotic properties survive when the model is misspecified?

  • BHHH needs one score vector per observation. What is an observation in the bus data: a bus, a month, or a bus-month?

Estimating the bus engine model with NFXP

For every value of the structural parameters θ=(RC,θ1,θ20,…,θ2J,β)\theta = (RC,\theta_1,\theta_{20},\dots,\theta_{2J},\beta) we can solve the model fast using NK iterations within the poly-algorithm, and based on the solution EVθ(x,d)EV_\theta(x,d) form the choice probabilities P(keep∣x,θ)P(\text{keep}|x,\theta) and P(replace∣x,θ)P(\text{replace}|x,\theta). Given data on mileage xx and choices dd we can then form the likelihood function and proceed with maximum likelihood estimation.

Data

Harold Zurcher kept maintenance records of 162 buses in 8 groups, with monthly observations of the mileage on each bus (the odometer reading) and data on the maintenance operations:

  1. Routine periodic maintenance (i.e. brake adjustment)

  2. Replacement or repair at the time of failure

  3. Major engine overhaul and/or replacement — the focus of the paper

The data are (xi,t,di,t)(x_{i,t},d_{i,t}), where xi,tx_{i,t} is the discretized mileage (bin indexes) and di,td_{i,t} the observed choice at this mileage for each bus ii in each month tt.

Likelihood function

The model delivers two conditional probabilities per observation, the choice given the state and the state transition given the previous state and choice, so

Ln(θ,EVθ)=∏i=1162∏t=2TiP(di,t∣xi,t)π(xi,t∣xi,t−1,di,t−1)\mathcal{L}_n(\theta, EV_\theta) = \prod_{i=1}^{162}\prod_{t=2}^{T_i} P(d_{i,t}|x_{i,t}) \pi(x_{i,t}|x_{i,t-1},d_{i,t-1})
ℓn(θ,EVθ)=log⁡Ln(θ,EVθ)=∑i=1162∑t=2Ti(log⁡P(di,t∣xi,t)+log⁡π(xi,t∣xi,t−1,di,t−1))\ell_n(\theta,EV_\theta) = \log \mathcal{L}_n(\theta,EV_\theta) = \sum_{i=1}^{162}\sum_{t=2}^{T_i} \big ( \log P(d_{i,t}|x_{i,t}) + \log \pi(x_{i,t}|x_{i,t-1},d_{i,t-1}) \big)

The dependence on EVθEV_\theta is written explicitly because the choice probabilities are a function of the solution of the model, not of θ\theta directly. The transition part depends on θ2\theta_2 only and does not involve the solution at all.

MLE estimator

θ^=arg⁡max⁡θℓn(θ,EVθ)\hat{\theta} = \arg\max_\theta \ell_n(\theta, EV_{\theta})

This is an unconstrained optimization, but it requires the computation of EVθEV_{\theta} for each value of the parameter θ\theta — a fixed point problem inside every function evaluation.

Nested loop

The outer loop is a hill-climbing algorithm. The log-likelihood function ℓn(θ,EVθ)\ell_n(\theta,EV_{\theta}) is maximized with respect to θ\theta by a quasi-Newton algorithm with the BHHH approximation of the Hessian, and each evaluation of ℓn(θ,EVθ)\ell_n(\theta,EV_{\theta}) requires the solution for the fixed point EVθEV_{\theta}.

The inner loop is the fixed point algorithm: the solver for the fixed point of the Bellman operator EVθ=Γ(EVθ)EV_{\theta} = \Gamma(EV_{\theta}), successive approximations (VFI) plus Newton–Kantorovich iterations in the poly-algorithm of Tuesday.

NFXP algorithm

Important details

  1. Performance: a gradient based Newton method to maximize the likelihood

  2. Analytical gradients: using the implicit function theorem and the chain rule for the outer loop, and the Fréchet derivative for the inner loop

  3. Use BHHH: the outer product of gradients approximation for the Hessian

  4. Numerical stability: recenter the logsum and the choice probabilities, the de-maxing trick of Class 6

  5. Further info: the NFXP manual, see the references below

Each of these is a difference between an estimator that runs in seconds and one that runs overnight. The comparison in Iskhakov et al. (2016) is exactly the difference between an NFXP with items 1–3 and one without.

Analytical gradient of the likelihood function

Differentiating the log-likelihood term by term,

∂∂θℓn(θ,EVθ)=∑i=1162∑t=2Ti(∂∂θlog⁡P(di,t∣xi,t)+∂∂θlog⁡π(xi,t∣xi,t−1,di,t−1))\frac{\partial}{\partial \theta} \ell_n(\theta,EV_\theta) = \sum_{i=1}^{162}\sum_{t=2}^{T_i} \big ( \frac{\partial}{\partial \theta} \log P(d_{i,t}|x_{i,t}) + \frac{\partial}{\partial \theta} \log \pi(x_{i,t}|x_{i,t-1},d_{i,t-1}) \big)

is straightforward with multiple applications of the chain rule. The key point is expressing the derivatives of the expected value function ∂EVθ∂θ\frac{\partial EV_{\theta}}{\partial \theta}, which is done with the Banach space version of the implicit function theorem applied to the fixed point equation:

∂EVθ∂θ=∂Γθ∂θ+∂Γθ∂EVθ∂EVθ∂θ⇒∂EVθ∂θ=(I−∂Γθ∂EVθ)−1∂Γθ∂θ\frac{\partial EV_{\theta}}{\partial \theta} = \frac{\partial \Gamma_{\theta}}{\partial \theta} + \frac{\partial \Gamma_{\theta}}{\partial EV_{\theta}} \frac{\partial EV_{\theta}}{\partial \theta} \Rightarrow \frac{\partial EV_{\theta}}{\partial \theta} = \Big( I - \frac{\partial \Gamma_{\theta}}{\partial EV_{\theta}} \Big)^{-1} \frac{\partial \Gamma_{\theta}}{\partial \theta}

Here Γθ(⋅)\Gamma_{\theta}(\cdot) is the finite approximation of the Bellman operator in expected value function space, and ∂Γθ∂EVθ\frac{\partial \Gamma_{\theta}}{\partial EV_{\theta}} is the finite approximation of its Fréchet derivative — the same matrix the NK step already computes and factorizes. The gradient of the likelihood is therefore nearly free once the model is solved by NK: one more solve with the same matrix and a different right hand side.

📖 John Rust “NFXP Pocket Guide” Download pdf

Replication of Rust (1987)

The estimator is in the folder session10-11/ of the code repository: nfxp.py is the model class of Tuesday with the data attached and the likelihood, its analytical score and BHHH on top, and the notebook replicate_rust1987.ipynb runs everything shown below. Run on Harold Zurcher’s records for bus groups 1–4, on the 175-cell mileage grid of the paper and with β=0.9999\beta = 0.9999:

from nfxp import read_busdata, estim_zurcher

data = read_busdata()                       # groups 1-4, 175 cells, Rust's cell convention
est = estim_zurcher(data)                   # the model with the data attached
result = est.estimate()                     # frequencies, then (RC, c), then everything
print(result)
NFXP estimates, beta = 0.9999, n = 175, N = 8156 bus-months
method bhhh, converged True, 0.066 s, 82 inner solves, 262 inner iterations
parameter     estimate        s.e.
RC             9.76867     1.22629
c              1.34283     0.31532
p0             0.10705     0.00343
p1             0.51522     0.00554
p2             0.36216     0.00532
p3             0.01434     0.00132
p4             0.00086     0.00032
log-likelihood -8607.8894

These are the numbers of the last row of Table X in Rust (1987) (θ11\theta_{11} is c, θ30,…,θ33\theta_{30},\dots,\theta_{33} are the first four transition probabilities):

Table X of Rust (1987)

The same estimator on each of the six samples of the table:

for beta in (0.9999, 0.0):
    for groups in ((1, 2, 3), (4,), (1, 2, 3, 4)):
        r = estim_zurcher(read_busdata(groups=groups), beta=beta).estimate()
        print(beta, groups, r.N, r.theta[:2], r.se[:2], r.loglik, r.theta[2:6])
  beta groups        N       RC    (se)        c      (se)     loglik  transition probabilities
0.9999 1,2,3      3864  11.7257   2.597   2.4569    0.9122  -3993.991  0.0937 0.4475 0.4459 0.0127
0.9999 4          4292  10.0896   1.581   1.1732    0.3265  -4495.135  0.1191 0.5762 0.2868 0.0158
0.9999 1,2,3,4    8156   9.7687   1.226   1.3428    0.3153  -8607.889  0.1071 0.5152 0.3622 0.0143
   0.0 1,2,3      3864   8.2969   1.048  56.1656   13.4205  -3996.353  0.0937 0.4475 0.4459 0.0127
   0.0 4          4292   7.6423   0.720  36.6692    7.0675  -4496.997  0.1191 0.5762 0.2868 0.0158
   0.0 1,2,3,4    8156   7.3113   0.507  36.0175    5.5145  -8614.238  0.1070 0.5152 0.3622 0.0143

Every entry replicates at the precision of the paper, once the data are read the way Rust’s code read them: mileage cell k=⌈x⋅175/450000⌉k = \lceil x \cdot 175 / 450000 \rceil used as a one-based index, so that the decision is evaluated at grid point k−1k-1 and the transition after a replacement is recorded from cell 0 to cell kk, one cell more than the model’s own reset. The one exception is RCRC for group 4 at β=.9999\beta = .9999, which the paper prints as 10.896 for 10.0896: every other number in that row agrees. Two things to notice in the myopic rows: the cost parameter is nearly thirty times larger when the future is not counted, and the log-likelihood is lower by 6.3, the paper’s test of myopia.

Counterfactuals

The estimates describe Zurcher’s behavior only through the model. What that behavior implies for the fleet is the ergodic distribution of mileage under the estimated replacement policy, against the mileage actually observed:

_, pk, _ = est.solve()                             # the policy at the estimates
q, q_keep, q_replace = ergodic_distribution(est, pk)   # defined in replicate_rust1987.ipynb
Ergodic distribution of mileage at the estimates against the data

The data sit to the left of the stationary distribution: most buses enter the sample with a new engine, and the panel is too short to reach the steady state. The counterfactual that the paper is after is the demand for engine replacement as a function of its price, obtained by re-solving the model on a grid of RCRC and reading the replacement rate off the ergodic distribution each time. Converting RCRC into dollars with the average replacement cost of $8062 for these groups (Table III of the paper) gives Figure 7 of the paper, for the dynamic and the myopic estimates:

RC_grid = np.linspace(0.5, 30, 60)                 # demand_curve() is in the notebook too
myopic = estim_zurcher(data, beta=0.0)
myopic.estimate()                                  # the myopic model, re-estimated
for m in (est, myopic):
    scale = 8062 / m.RC                            # dollars per unit of RC at the estimate
    plt.plot(RC_grid * scale, demand_curve(m, RC_grid), label=f'beta = {m.beta}')
Demand for engine replacement as a function of its price, dynamic and myopic model

The two models fit the data equally well at the observed price and disagree everywhere else: the myopic bus manager reacts to a price change far more, because in his model the only reason to replace is today’s cost. This is why the discount factor matters for policy even when the likelihood can barely tell β=0.9999\beta = 0.9999 from β=0\beta = 0. A known issue: the demand curves do not exactly replicate Figure 7 of the paper, although the estimates they are computed from reproduction of its tables.

  • θ2\theta_2 enters the likelihood through π\pi only. Can it be estimated without solving the model at all, and what does that suggest for the estimation strategy?

  • β\beta is listed among the structural parameters. Would you try to estimate it?

  • The inner loop is warm-started from the previous EVθEV_\theta. When is that a good idea, and when does it hurt?

References
  1. Rust, J. (1987). Optimal Replacement of GMC Bus Engines: An Empirical Model of Harold Zurcher. Econometrica, 55(5), 999. 10.2307/1911259
  2. Newey, W. K., & McFadden, D. (1994). Large sample estimation and hypothesis testing. In R. F. Engle & D. L. McFadden (Eds.), Handbook of Econometrics (Vol. 4, pp. 2111–2245). Elsevier. 10.1016/S1573-4412(05)80005-4
  3. Berndt, E. R., Hall, B. H., Hall, R. E., & Hausman, J. A. (1974). Estimation and Inference in Nonlinear Structural Models. In Annals of Economic and Social Measurement, Volume 3, Number 4 (Vol. 3, pp. 653–665). National Bureau of Economic Research. https://www.nber.org/chapters/c10206
  4. Iskhakov, F., Lee, J., Rust, J., Schjerning, B., & Seo, K. (2016). Constrained optimization approaches to estimation of structural models: Comment. Econometrica, 84(1), 365–370. 10.3982/ECTA12605
  5. Rust, J. (2000). Nested Fixed Point Algorithm Documentation Manual [Techreport]. Yale University.
  6. Wooldridge, J. M. (2010). Econometric Analysis of Cross Section and Panel Data (2nd ed.). MIT Press.