14  Simulated Integration and Maximum Simulated Likelihood

Many of the objects we need for estimation — likelihoods, moments, expected values — are integrals that cannot be computed in closed form. This chapter shows how to approximate these integrals by simulation, how to reduce the noise of the approximation, and what happens when the simulated integral is plugged into a likelihood function.

14.1 Integration by Simulation

At the heart of simulation-based estimation is the problem of computing integrals and high-dimensional sums. Suppose we need to evaluate:

\[f(y|\mathbf{x},\theta) = \int h(y|\mathbf{x},\theta,\mathbf{u})g(\mathbf{u})d\mathbf{u}\]

where \(\mathbf{u}\) is a vector of unobservables with density \(g\). If we want to evaluate this integral with quadrature methods (Section 2.5.1) then we face a curse of dimensionality. When the number of dimensions in \(\mathbf{u}\) is large then the problem is simply intractable. One solution is to approximate by Monte Carlo integration: draw \(\mathbf{u}^{1},\ldots,\mathbf{u}^{R}\) from \(g\) and compute:

\[\hat{f}(y|\mathbf{x},\theta) = \frac{1}{R}\sum_{r=1}^{R}h(y|\mathbf{x},\theta,\mathbf{u}^{r})\]

By the law of large numbers, \(\hat{f}\rightarrow_{p} f\) as \(R\rightarrow\infty\). This is unbiased by construction: \(\mathbb{E}_{\mathbf{u}}[\hat{f}]=f\).

14.1.1 Importance Sampling

Sometimes we want to draw from an alternative density \(w(\mathbf{u})\) instead of \(g(\mathbf{u})\) — for instance because \(g\) is hard to sample from, or because draws from \(w\) reduce the variance of the estimator. In this case:

\[\hat{f}(y|\mathbf{x},\theta) = \frac{1}{R}\sum_{r=1}^{R}h(y|\mathbf{x},\theta,\mathbf{u}^{r})\frac{g(\mathbf{u}^{r})}{w(\mathbf{u}^{r})},\qquad \mathbf{u}^{r}\sim w\]

This is still unbiased and consistent. The ratio \(g/w\) is called the importance weight.

Variance reduction. Why can the choice of \(w\) reduce variance? The variance of the importance-sampling estimator depends on the variance of \(h \cdot g/w\) under draws from \(w\). Intuitively, if \(w\) concentrates draws in regions where the integrand \(h \cdot g\) is large, the estimator “wastes” fewer draws on regions that contribute little to the integral, reducing variance. The ideal importance density is proportional to \(|h| \cdot g\), which puts the most weight exactly where it matters most. In practice, one looks for a convenient \(w\) that roughly approximates this shape.

Example 14.1 To illustrate, consider estimating a tail probability: \(P(Z > 3)\) where \(Z\sim\mathcal{N}(0,1)\). The true value is approximately \(0.00135\).

Naive Monte Carlo draws \(Z^{1},\ldots,Z^{R}\sim\mathcal{N}(0,1)\) and computes \(\hat{p}=\frac{1}{R}\sum_{r}\mathbf{1}\{Z^{r}>3\}\). Because the event \(\{Z>3\}\) is rare, most draws contribute zero to the sum — the estimator “wastes” draws in the center of the distribution where \(\mathbf{1}\{Z>3\}\cdot\phi(Z)\) is negligible.

Importance sampling instead draws from \(w=\mathcal{N}(3,1)\), which concentrates mass in the tail where the integrand is large. The estimator becomes: \[\hat{p}_{IS}=\frac{1}{R}\sum_{r}\mathbf{1}\{Z^{r}>3\}\frac{\phi(Z^{r})}{\phi_{w}(Z^{r})},\qquad Z^{r}\sim\mathcal{N}(3,1)\]

We compare both estimators across 2,000 independent replications, each using \(R=2{,}000\) draws.

using Distributions, Random, Plots, Statistics
include("../scripts/plot_theme.jl")

Random.seed!(42)
c = 3.0
p_true = 1 - cdf(Normal(), c)

R = 2000; n_reps = 2000
g = Normal(0, 1)      # target distribution
w = Normal(c, 1)       # importance distribution (shifted to the tail)

# Naive MC: draw from g, average the indicators
naive_estimates = [mean(rand(g, R) .> c) for _ in 1:n_reps]

# Importance sampling: draw from w, reweight
is_estimates = map(1:n_reps) do _
    z = rand(w, R)
    weights = pdf.(g, z) ./ pdf.(w, z)
    mean((z .> c) .* weights)
end

println("True probability: P(Z > $c) = $(round(p_true, sigdigits=5))")
println("Naive MC:       mean = $(round(mean(naive_estimates), sigdigits=5)),  std = $(round(std(naive_estimates), sigdigits=3))")
println("Importance MC:  mean = $(round(mean(is_estimates), sigdigits=5)),  std = $(round(std(is_estimates), sigdigits=3))")
println("Variance ratio (naive / IS): $(round(var(naive_estimates) / var(is_estimates), digits=1))×")
True probability: P(Z > 3.0) = 0.0013499
Naive MC:       mean = 0.0013565,  std = 0.000817
Importance MC:  mean = 0.0013504,  std = 5.47e-5
Variance ratio (naive / IS): 223.3×
p1 = histogram(naive_estimates, normalize=:pdf, alpha=0.6, label=false,
               color=MCM.teal, xlabel="Estimate of P(Z > $c)", title="Naive MC")
vline!(p1, [p_true], color=MCM.charcoal, linewidth=2, linestyle=:dash, label="True value")

p2 = histogram(is_estimates, normalize=:pdf, alpha=0.6, label=false,
               color=MCM.orange, xlabel="Estimate of P(Z > $c)", title="Importance Sampling")
vline!(p2, [p_true], color=MCM.charcoal, linewidth=2, linestyle=:dash, label="True value")

plot(p1, p2, layout=(1,2), size=(800, 350))

The contrast is stark. The naive estimator is highly discrete — it can only take values that are multiples of \(1/R\) — and its distribution is spread widely around the truth. The importance sampling estimator is continuous (because the importance weights are continuous) and tightly concentrated. Both are unbiased, but importance sampling achieves a dramatic reduction in variance by directing draws to the region that matters.

Differentiability. Importance sampling also plays a role in making simulated integrals differentiable with respect to the parameters \(\theta\). When the integrand involves indicator functions — as in discrete choice models where \(h(y|\mathbf{x},\theta,\mathbf{u})=\mathbf{1}\{\cdot\}\) — the crude Monte Carlo approximation is a step function in \(\theta\), which creates problems for gradient-based optimization. Through a change of variables, it is sometimes possible to move the dependence on \(\theta\) out of the indicator and into smooth importance weights, yielding a simulated integral that is differentiable in \(\theta\). The GHK simulator for multivariate probit models is a prominent example of this strategy (see Section 14.2.1 below).

14.2 Maximum Simulated Likelihood

A natural first idea is to replace the likelihood with its simulated analogue. The maximum simulated likelihood (MSL) estimator is:

\[\hat{\theta}_{MSL} = \arg\max_{\theta}\sum_{n=1}^{N}\log\hat{f}(y_{n}|\mathbf{x}_{n},\theta)\]

where \(\hat{f}\) is the simulated probability from above.

A Subtlety with MSL

There is an important issue with MSL: because \(\log\) is concave, Jensen’s inequality gives \(\mathbb{E}[\log\hat{f}]\leq \log\mathbb{E}[\hat{f}]=\log f\). This means the simulated log-likelihood is biased downward, and the MSL estimator is inconsistent for fixed \(R\). Consistency requires that the number of simulation draws grows with the sample: both \(N,R\rightarrow\infty\) with \(\sqrt{N}/R\rightarrow 0\).

This is in contrast to the method of simulated moments, which we discuss next, where a fixed number of simulation draws is sufficient for consistency.

Under standard regularity conditions and \(\sqrt{N}/R\rightarrow 0\), the MSL estimator has the same asymptotic distribution as the (infeasible) MLE:

\[\sqrt{N}(\hat{\theta}_{MSL}-\theta_{0})\rightarrow_{d}\mathcal{N}(\mathbf{0},\ \mathcal{I}(\theta_{0})^{-1})\]

In practice, one should use enough draws that the simulation error is small relative to the sampling variability. A common rule of thumb is to set \(R\) large enough that results are insensitive to further increases.

14.2.1 Differentiability of the Simulated Likelihood

Warning

A separate challenge with MSL arises when the model involves discrete outcomes. Consider a simple probit: \(Y=\mathbf{1}\{X\beta+\varepsilon>0\}\) with \(\varepsilon\sim\mathcal{N}(0,1)\). The true choice probability \(\Phi(X\beta)\) is a smooth function of \(\beta\). But if we approximate it by crude Monte Carlo — drawing \(\varepsilon^{1},\ldots,\varepsilon^{R}\sim\mathcal{N}(0,1)\) and computing \(\hat{P}=\frac{1}{R}\sum_{r}\mathbf{1}\{X\beta+\varepsilon^{r}>0\}\) — the result is a step function in \(\beta\). Each indicator \(\mathbf{1}\{X\beta+\varepsilon^{r}>0\}\) switches from 0 to 1 at \(\beta=-\varepsilon^{r}/X\), so \(\hat{P}\) jumps at finitely many points and is flat everywhere else. Its derivative is zero almost everywhere, making gradient-based optimization of the simulated log-likelihood impossible.

The figure below illustrates this for \(X=1\) and \(R=20\) draws. The true probability \(\Phi(\beta)\) is smooth, but the simulated probability is a step function that jumps at each \(\beta=-\varepsilon^{r}\). The kernel-smoothed simulator replaces the indicator with \(\Phi(\cdot/h)\), restoring differentiability at the cost of a small bias.

using Distributions, Plots, Random

Random.seed!(123)
R = 20
ε = rand(Normal(), R)

β_grid = range(-3, 3, length=1000)
P_true = cdf.(Normal(), β_grid)
P_sim = [mean(β .+ ε .> 0) for β in β_grid]
h = 0.3
P_smooth = [mean(cdf.(Normal(), (β .+ ε) ./ h)) for β in β_grid]

plot(β_grid, P_true, label="True Φ(β)", linewidth=2.5, color=MCM.charcoal,
     xlabel="β", ylabel="P(Y=1 | X=1)")
plot!(β_grid, P_sim, label="Crude MC (R=$R)", linewidth=1.5,
     color=MCM.teal, alpha=0.8)
plot!(β_grid, P_smooth, label="Kernel-smoothed (h=$h)", linewidth=2,
     color=MCM.orange, linestyle=:dash)

This problem is not specific to probit — it arises whenever the simulated likelihood involves averaging indicator functions. Solutions include:

  1. Kernel smoothing: replace the indicator \(\mathbf{1}\{\cdot>0\}\) with a smooth approximation such as \(\Phi(\cdot/h)\) for a small bandwidth \(h\) (the dashed red curve above).
  2. Importance sampling / change of variables: restructure the integral so that \(\beta\) appears in smooth weights rather than inside an indicator. The GHK simulator for multivariate probit uses sequential conditioning to achieve this.
  3. Derivative-free optimization: use methods like Nelder-Mead that do not require gradients. This is simple but can be slow and unreliable in high dimensions.