PS 818 - Data Analysis with Statistical Models
September 14, 2026
\[ \DeclareMathOperator*{\argmin}{arg\,min} \DeclareMathOperator*{\argmax}{arg\,max} \]
It is common to see the linear model written in its fully parametric form.
Stochastic:
\[y_i \sim \text{Normal}(\mu_i, \sigma^2)\]
Systematic:
\[\mu_i = x_i^{\prime}\beta\]
What’s assumed to be known?
What’s assumed to have a particular distribution?
We are interested in estimating and conducting inference on the parameters: \(\beta\) and (less importantly) \(\sigma^2\).
We can specify a broad set of models for \(y_i\) using this framework
Stochastic
\[y_i \sim f(\theta_i, \alpha)\]
Systematic
\[\theta_i = g(x_i, \beta)\]
What are these quantities?
Later, we will spend some time with a particular class of models called “Generalized Linear Models” where the systematic component has the form
\[\theta_i = g(x_i^{\prime}\beta)\]
Continuous on an unbounded support \((-\infty, \infty)\)
Two parameters: Mean \(\mu\) and Variance \(\sigma^2\)
\[f(x;\mu, \sigma) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left\{- \frac{1}{2}\left(\frac{x - \mu}{\sigma}\right)^2 \right\}\]
Discrete, defined on the support of the natural numbers (positive integers + zero)
Single parameter: Mean and Variance \(\lambda\)
\[f(x; \lambda) = \frac{\lambda^x\exp\{-\lambda\}}{x!}\]
Consider data \(\mathbf{y} = \{y_1, y_2, \dotsc, y_n\}\) which we assume comes from a known distribution with density \(f(\mathbf{y} | \theta)\) with unknown parameter \(\theta\)
The likelihood function is a function of \(\theta\) that is evaluated at the observed values of \(\mathbf{y}\)
\[\mathcal{L}(\theta| \mathbf{y}) = f(\mathbf{y} | \theta)\]
Given some input \(\theta\), the likelihood function returns the density of the observed data evaluated at that value.
The likelihood function is not a probability density
The likelihood function is not \(f(\theta | \mathbf{y})\)
Even when we (later) move to a Bayesian framework, \(f(\theta | \mathbf{y}) \neq f(\mathbf{y} | \theta)\)
Remember Bayes’ Rule:
\[f(\theta | \mathbf{y}) = \frac{f(\mathbf{y} | \theta)}{f(\mathbf{y})} \times f(\theta)\]
Or alternatively, since \(f(\mathbf{y})\) is just a normalizing constant, you’ll see this written as:
\[\underbrace{f(\theta | \mathbf{y})}_{\text{posterior}} \propto \underbrace{f(\mathbf{y}|\theta)}_{\text{likelihood}} \times \underbrace{f(\theta)}_{\text{prior}}\]
We often make the assumption that our data are independently and identically distributed
This allows us to factor the likelihood
\[\mathcal{L}(\theta|\mathbf{y}) = f(\mathbf{y} | \theta) = \prod_{i=1}^n f(y_i | \theta)\]
Since our eventual goal will be to find an optimum of the likelihood, we can apply any strictly increasing function to it, since that preserves the location of the maximum.
For theory reasons, you’ll see two forms of the log-likelihood
The total log-likelihood
\[\ell_n(\theta) = \sum_{i=1}^n \log f(y_i | \theta)\]
The average log-likelihood
\[\bar{\ell}_n(\theta) = \frac{1}{n}\ell_n(\theta) = \frac{1}{n}\sum_{i=1}^n \log f(y_i | \theta)\]
These have the same maximizer
The score for a single observation is the gradient of its log-density with respect to \(\theta\)
\[s_i(\theta) = \frac{\partial}{\partial\theta} \log f(y_i | \theta)\]
For a \(k\)-dimensional \(\theta\), \(s_i(\theta)\) is a \(k \times 1\) vector.
The Hessian for a single observation is the matrix of second derivatives
\[H_i(\theta) = \frac{\partial^2}{\partial\theta\partial\theta^{\prime}} \log f(y_i | \theta)\]
Summing and averaging as before:
\[S_n(\theta) = \sum_{i=1}^n s_i(\theta) \qquad \bar{S}_n(\theta) = \frac{1}{n}\sum_{i=1}^n s_i(\theta)\]
\[H_n(\theta) = \sum_{i=1}^n H_i(\theta) \qquad \bar{H}_n(\theta) = \frac{1}{n}\sum_{i=1}^n H_i(\theta)\]
\(S_n(\theta)\) is exactly the gradient of \(\ell_n(\theta)\), and \(H_n(\theta)\) its Hessian.
We want to come up with an estimator \(\hat{\theta}\) for the parameter \(\theta\)
The Maximum Likelihood Estimator (MLE) \(\hat{\theta}\) is defined as the value of \(\theta\) that maximizes the log-likelihood
\[\hat{\theta} = \argmax_{\theta \in \Theta} \ \ell_n(\theta)\]
Under i.i.d. observations (and regularity conditions), the MLE has some desirable properties:
First, we’ll start with some properties of the score.
One property that comes up frequently: evaluated at the parameter that generated the data, the score has mean zero
\[\mathbb{E}_{\theta}\big[s_i(\theta)\big] = 0\]
Start from the definition of the score
\[\mathbb{E}_{\theta}\big[s_i(\theta)\big] = \int \left[\frac{\partial}{\partial\theta} \log f(y|\theta)\right] f(y|\theta) \, dy\]
Apply the chain rule to \(\log f\), then cancel \(f(y|\theta)\)
\[= \int \frac{\partial}{\partial\theta} f(y|\theta) \, dy\]
Swap the derivative and the integral (regularity condition - we assume we’re able to do this)
\[= \frac{\partial}{\partial\theta} \int f(y|\theta) \, dy\]
The density integrates to one
\[= \frac{\partial}{\partial\theta} \, 1 \; = \; 0\]
By the weak law of large numbers, for each \(\theta\)
\[\bar{\ell}_n(\theta) = \frac{1}{n} \sum_{i=1}^n \log f(y_i | \theta) \overset{p}{\rightarrow} \mathbb{E}_{\theta_0}[\log f(y_i | \theta)] \]
The MLE maximizes the left-hand side, so (under regularity conditions) \(\hat{\theta}\) converges to whatever maximizes \(\mathbb{E}_{\theta_0}[\log f(y_i | \theta)]\)
We can show that the true parameter \(\theta_0\) maximizes \(\mathbb{E}_{\theta_0}[\log f(y_i | \theta)]\)
Consider any other value of \(\theta\) and apply properties of logs
\[\mathbb{E}_{\theta_0}[\log f(y_i | \theta)] - \mathbb{E}_{\theta_0}[\log f(y_i | \theta_0)] = \mathbb{E}_{\theta_0}\left[\log \frac{f(y_i|\theta)}{f(y_i|\theta_0)}\right]\]
By Jensen’s inequality (\(\log\) is concave),
\[\mathbb{E}_{\theta_0}\left[\log \frac{f(y_i|\theta)}{f(y_i|\theta_0)}\right] \le \log \mathbb{E}_{\theta_0}\left[\frac{f(y_i|\theta)}{f(y_i|\theta_0)}\right] = \log \int f(y|\theta) \, dy = \log 1 = 0\]
So \(\mathbb{E}_{\theta_0}[\log f(y_i | \theta)] \le \mathbb{E}_{\theta_0}[\log f(y_i | \theta_0)]\) for all \(\theta\)
Therefore the MLE is consistent: \(\hat{\theta} \overset{p}{\to} \theta_0\).
Note a few important conditions for identification
Identifiability
\[f(\cdot\,|\theta) \neq f(\cdot\,| \theta_0) \ \forall \ \theta \neq \theta_0\]
Fixed parameter space
\(\theta_0\) is in the interior of the parameter space
After consistency, we want the variance and asymptotic distribution of \(\hat{\theta}\).
Define the per-observation information as the variance of the score at the true parameter \(\theta_0\)
\[\mathcal{I}(\theta_0) = \mathbb{E}_{\theta_0}\big[s_i(\theta_0) s_i(\theta_0)^{\prime}\big]\]
Under some further regularity conditions this equals the negative expected Hessian
\[\mathcal{I}(\theta_0) = -\mathbb{E}_{\theta_0}\big[H_i(\theta_0)\big]\]
Intuitively: captures the curvature of the log-likelihood around the truth.
The total (sample) information for \(n\) i.i.d. observations is
\[\mathcal{I}_n(\theta_0) = -\mathbb{E}_{\theta_0}\big[H_n(\theta_0)\big] = n \, \mathcal{I}(\theta_0)\]
Now we can show that the MLE is asymptotically normal.
\[\sqrt{n}(\hat{\theta} - \theta_0) \overset{d}{\rightarrow} \text{Normal}\big(0, \mathcal{I}(\theta_0)^{-1}\big)\]
Our first step is to take a first-order Taylor approximation of the score around the true parameter \(\theta_0\), written as a function of our estimator \(\hat{\theta}\)
\[\bar{S}_n(\hat{\theta}) \approx \bar{S}_n(\theta_0) + \bar{H}_n(\theta_0)(\hat{\theta} - \theta_0)\]
Using the fact that the score is zero at the MLE
\[0 = \bar{S}_n(\theta_0) + \bar{H}_n(\theta_0)(\hat{\theta} - \theta_0)\]
Rearranging gives
\[(\hat{\theta} - \theta_0) = \big[-\bar{H}_n(\theta_0)\big]^{-1}\bar{S}_n(\theta_0)\]
Multiplying by \(\sqrt{n}\)
\[\sqrt{n}(\hat{\theta} - \theta_0) = \big[-\bar{H}_n(\theta_0)\big]^{-1}\big[\sqrt{n}\,\bar{S}_n(\theta_0)\big]\]
First, by the law of large numbers applied to the average Hessian,
\[-\bar{H}_n(\theta_0) = -\frac{1}{n} \sum_{i=1}^n H_i(\theta_0) \overset{p}{\to} -\mathbb{E}_{\theta_0}\big[H_i(\theta_0)\big] = \mathcal{I}(\theta_0)\]
Second, by the central limit theorem applied to the mean-zero scores,
\[\sqrt{n} \, \bar{S}_n(\theta_0) = \frac{1}{\sqrt{n}} \sum_{i=1}^n s_i(\theta_0) \overset{d}{\to} \text{Normal}\big(0, \, \text{Var}_{\theta_0}(s_i(\theta_0))\big) = \text{Normal}\big(0, \mathcal{I}(\theta_0)\big)\]
Lastly, by Slutsky’s theorem,
\[\sqrt{n}(\hat{\theta} - \theta_0) \overset{d}{\to} \text{Normal}\big(0, \mathcal{I}(\theta_0)^{-1}\mathcal{I}(\theta_0)\mathcal{I}(\theta_0)^{-1}\big) = \text{Normal}\big(0, \mathcal{I}(\theta_0)^{-1}\big)\]
So our large-sample approximation for the distribution of the MLE is
\[\hat{\theta} \overset{a}{\sim} \text{Normal}\big(\theta_0, \ \mathcal{I}_n(\theta_0)^{-1}\big)\]
Standard errors are the square roots of the diagonal of \(\mathcal{I}_n(\hat{\theta})^{-1}\).
Can another estimator do better asymptotically?
An important result in statistics relates to the smallest possible variance that an unbiased estimator could reach
The Cramér-Rao lower bound on the variance of any unbiased estimator \(\hat{\theta}\) of \(\theta\) is
\[\text{Var}(\hat{\theta}) \succeq \mathcal{I}_n(\theta)^{-1}\]
We’ll focus the proof on the scalar case
Under unbiasedness
\[\mathbb{E}_{\theta}[\hat{\theta}(\mathbf{y}) - \theta] = \int(\hat{\theta}(\mathbf{y}) - \theta) f(\mathbf{y}| \theta)d\mathbf{y} = 0\]
Since unbiasedness holds for every value of \(\theta\), differentiating with respect to \(\theta\) also gives zero
\[\frac{\partial}{\partial\theta} \int(\hat{\theta}(\mathbf{y}) - \theta) f(\mathbf{y} |\theta)d\mathbf{y} = 0\]
Under the regularity conditions that let us exchange differentiation and integration
\[\int \frac{\partial}{\partial\theta} \bigg[(\hat{\theta}(\mathbf{y}) - \theta) f(\mathbf{y}| \theta)\bigg]d\mathbf{y} = 0\]
Product rule
\[\int (\hat{\theta}(\mathbf{y}) - \theta) \frac{\partial}{\partial\theta} f(\mathbf{y}| \theta) \, d\mathbf{y} - \int f(\mathbf{y}| \theta)d\mathbf{y} = 0\]
PDFs integrate to 1 over their support
\[\int (\hat{\theta}(\mathbf{y}) - \theta) \frac{\partial}{\partial\theta} f(\mathbf{y}| \theta) \, d\mathbf{y} = 1\]
The same chain rule identity as before
\[\frac{\partial}{\partial \theta} f(\mathbf{y}| \theta) = f(\mathbf{y}| \theta) \frac{\partial}{\partial \theta} \log f(\mathbf{y}|\theta) = f(\mathbf{y}|\theta) \, S_n(\theta)\]
Plugging back in,
\[\int (\hat{\theta}(\mathbf{y}) - \theta) \, S_n(\theta) \, f(\mathbf{y}| \theta)d\mathbf{y} = 1\]
By the “law of the unconscious statistician” this is just an expectation
\[\mathbb{E}_{\theta}\big[(\hat{\theta}(\mathbf{y}) - \theta) \, S_n(\theta)\big] = 1\]
The Cauchy-Schwarz inequality for expectations says that for random variables \(U\) and \(V\)
\[\big|\mathbb{E}[UV]\big|^2 \le \mathbb{E}[U^2]\,\mathbb{E}[V^2]\]
Apply it with \(U = \hat{\theta}(\mathbf{y}) - \theta\) and \(V = S_n(\theta)\)
\[1 = \big|\mathbb{E}_\theta[U V]\big|^2 \le \mathbb{E}_{\theta}\big[(\hat{\theta}(\mathbf{y}) - \theta)^2\big] \times \mathbb{E}_{\theta}\big[S_n(\theta)^2\big]\]
What are the pieces here?
So
\[\text{Var}(\hat{\theta}) \times \mathcal{I}_n(\theta) \ge 1 \quad \Longrightarrow \quad \text{Var}(\hat{\theta}) \ge \frac{1}{\mathcal{I}_n(\theta)}\]
Compare this to the large-sample distribution of the MLE from earlier:
\[\hat{\theta}_{MLE} \overset{a}{\sim} \text{Normal}\big(\theta_0, \ \mathcal{I}_n(\theta_0)^{-1}\big)\]
The MLE attains the bound asymptotically.
Let’s consider the classical normal regression model with homoskedastic errors
\[y_i \sim \text{Normal}(\mu_i, \sigma^2), \qquad \mu_i = x_i^{\prime}\beta\]
Under i.i.d. the joint density factors, and logs turn the product into a sum
\[\ell_n(\beta, \sigma^2) = \log \prod_{i=1}^n f(y_i| \beta, \sigma^2) = \sum_{i=1}^n \log f(y_i| \beta, \sigma^2)\]
Plug in the Normal density for each observation
\[\ell_n(\beta, \sigma^2) = \sum_{i=1}^n \log \bigg[\frac{1}{\sigma\sqrt{2\pi}} \exp\left\{- \frac{1}{2}\left(\frac{y_i - x_i^\prime\beta}{\sigma}\right)^2 \right\}\bigg]\]
Properties of logs – note \(\log(\sigma\sqrt{2\pi}) = \log\sigma + \tfrac{1}{2}\log(2\pi)\)
\[\ell_n(\beta, \sigma^2) = \sum_{i=1}^n \left[-\log(\sigma) - \tfrac{1}{2}\log(2\pi) -\frac{1}{2}\bigg(\frac{y_i - x_i^\prime\beta}{\sigma}\bigg)^2\right]\]
The \(\tfrac{1}{2}\log(2\pi)\) term does not depend on \(\beta\) or \(\sigma\), so it cannot change the location of the maximum. Ignoring it,
\[\ell_n(\beta, \sigma^2) = -\frac{1}{2\sigma^2} \sum_{i=1}^n (y_i - x_i^\prime\beta)^2 -n\log(\sigma)\]
And the corresponding average log-likelihood
\[\bar{\ell}_n(\beta, \sigma^2) = \frac{1}{n} \sum_{i=1}^n \bigg[-\frac{1}{2\sigma^2} (y_i - x_i^\prime\beta)^2 - \log(\sigma)\bigg]\]
What’s familiar here?
Let’s derive the score. The per-observation log-density, again ignoring the constant, with residuals \(e_i = y_i - x_i^\prime\beta\):
\[\log f(y_i|\beta, \sigma) = -\frac{e_i^2}{2\sigma^2} - \log(\sigma)\]
Differentiating with respect to \(\beta\) (chain rule, \(\partial e_i / \partial\beta = -x_i\)):
\[\frac{\partial}{\partial\beta} \log f(y_i|\beta,\sigma) = \frac{x_i \, e_i}{\sigma^2}\]
Differentiating with respect to \(\sigma\):
\[\frac{\partial}{\partial\sigma} \log f(y_i|\beta,\sigma) = \frac{e_i^2}{\sigma^3} - \frac{1}{\sigma}\]
Setting the sum of the first to zero gives the OLS normal equations \(\mathbf{X}^\prime\mathbf{e} = 0\)
Differentiating once more gives the blocks of \(H_n\):
\[\frac{\partial^2 \ell_n}{\partial\beta\partial\beta^\prime} = -\frac{\mathbf{X}^\prime\mathbf{X}}{\sigma^2}, \qquad \frac{\partial^2 \ell_n}{\partial\beta \, \partial\sigma} = -\frac{2\mathbf{X}^\prime\mathbf{e}}{\sigma^3}, \qquad \frac{\partial^2 \ell_n}{\partial\sigma^2} = \frac{n}{\sigma^2} - \frac{3\sum_i e_i^2}{\sigma^4}\]
Evaluated at the MLE
So the exact Hessian at the MLE is block diagonal:
\[H_n(\hat{\theta}) = \begin{bmatrix} -\mathbf{X}^\prime\mathbf{X}/\hat\sigma^2 & 0 \\ 0 & -2n/\hat\sigma^2 \end{bmatrix}\]
Which gives us closed-form standard errors
\[\widehat{\text{Var}}(\hat\beta) = \hat\sigma^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]
Our familiar regression variance-covariance matrix for \(\hat{\beta}\)!
maxLik package is a nice wrapper for the various optimizers built in to RmaxLik, takes a function whose first argument is the parameter vector.
norm_loglik and all other arguments to maxLik().
method = "NR" to select the Newton-Raphson optimizer[1] 67.799 -0.462 2.505
term se_maxLik se_ols pct_error
(Intercept) (Intercept) 0.49869 0.9059 -44.9
pctWhiteNH pctWhiteNH 0.00657 0.0112 -41.3
lm)se_from_start <- function(ls0, grad=NULL){
fit <- maxLik(norm_loglik, grad=grad, start=c(0, 0, ls0), method="NR",
Y=Y_vec, X=X_matrix)
se <- suppressWarnings(sqrt(diag(solve(-maxLik::hessian(fit)))))
c(beta1_hat = coef(fit)[2], SE_beta1 = se[2])
}
starts <- c(2.0, 2.303, exp(1), 2.708, 3.0)
round(t(sapply(starts, se_from_start)), 6) beta1_hat SE_beta1
[1,] -0.462 0.00844
[2,] -0.462 0.00845
[3,] -0.462 0.00845
[4,] -0.462 NaN
[5,] -0.462 0.00657
term numeric analytic ols_truth
(Intercept) (Intercept) 0.49869 0.9056 0.9059
pctWhiteNH pctWhiteNH 0.00657 0.0112 0.0112
maxLik is still finite-differencing to get the Hessian – but now it differences the exact gradient - less room for numerical error. beta1_hat SE_beta1
[1,] -0.462 0.0112
[2,] -0.462 0.0112
[3,] -0.462 0.0112
[4,] -0.462 0.0112
[5,] -0.462 0.0112
se_z_numeric <- sqrt(diag(solve(-maxLik::hessian(mle_z_numeric))))
se_z_analytic <- sqrt(diag(solve(-maxLik::hessian(mle_z_analytic))))
data.frame(
term = c("(Intercept)", "pctWhiteNH", "log(sigma)"),
numeric = se_z_numeric,
analytic = se_z_analytic,
pct_diff = 100*(se_z_numeric - se_z_analytic)/se_z_analytic
) term numeric analytic pct_diff
1 (Intercept) 0.0144 0.0144 -0.000879
2 pctWhiteNH 0.0144 0.0144 -0.001603
3 log(sigma) 0.0127 0.0127 0.001887
To get back to the units of interest, undo the re-scaling:
\[\hat\beta_1^{raw} = \hat\beta_1^{z} \times \frac{s_Y}{s_X}, \qquad \widehat{\text{SE}}(\hat\beta_1^{raw}) = \widehat{\text{SE}}(\hat\beta_1^{z}) \times \frac{s_Y}{s_X}\]
quantity from_z ols_truth
Estimate slope -0.4617 -0.4617
Std. Error SE(slope) 0.0112 0.0112
Return to the asymptotic variance derivation. We had the sandwich
\[\text{Var}\big(\sqrt{n}(\hat{\theta}-\theta_0)\big) \approx \underbrace{\big[-\mathbb{E}_{\theta_0}[H_i(\theta_0)]\big]^{-1}}_{\text{bread}} \underbrace{\text{Var}_{\theta_0}\big(s_i(\theta_0)\big)}_{\text{meat}} \underbrace{\big[-\mathbb{E}_{\theta_0}[H_i(\theta_0)]\big]^{-1}}_{\text{bread}}\]
Previously we used the information matrix equality – \(\text{meat} = \text{bread}^{-1} = \mathcal{I}(\theta_0)\) – to collapse this to \(\mathcal{I}(\theta_0)^{-1}\).
Instead, we can estimate each piece separately with sample analogues:
\[\widehat{\text{Var}}(\hat{\theta}) = \bigg[-\sum_{i=1}^n H_i(\hat\theta)\bigg]^{-1}\bigg[\sum_{i=1}^n s_i(\hat{\theta}) s_i(\hat{\theta})^{\prime}\bigg]\bigg[-\sum_{i=1}^n H_i(\hat\theta)\bigg]^{-1}\]
Consistent under misspecification of the outcome distribution, but finite-sample properties can be poor absent corrections (e.g. \(\frac{n}{n-k}\) scaling known as HC1).
sandwich::estfun returns the per-observation gradient[1] 3114 3
[1] -1.0e-06 -5.1e-05 3.1e-05
term classical robust robust_hc1
1 (Intercept) 0.9056 1.0348 1.0351
2 pctWhiteNH 0.0112 0.0122 0.0122
3 log(sigma) 0.0127 0.0138 0.0139
PS 818 - University of Wisconsin-Madison