R Matrix Lab 3 — Prediction and Gaussian Likelihood
R Matrix Lab 3 — Prediction and Gaussian Likelihood
Question
How can one covariance matrix produce both a predictor and a likelihood?
Let the observed vector be and target be . Partition their joint covariance:
Then
and
Example 1 — Predictor weights and Schur complement
Use an AR(2) with and innovation variance 1.5. Predict from
The model says that only the first two coordinates should retain non-zero weights.
Solve and audit the best linear predictor
The third weight should be zero up to numerical precision, and the Schur complement should reproduce the innovation variance. Both are model-implied identities.
Example 2 — Three estimators answer three finite-sample problems
For a centred AR(1):
Compare:
and the exact Gaussian maximum-likelihood estimate based on
Compare conditional, Yule-Walker, and exact Gaussian estimates
The estimates are not expected to match exactly:
| Estimator | Initial-condition treatment | Main sample summary |
|---|---|---|
| conditional LS | conditions on | transition residual sum of squares |
| Yule–Walker | replaces population moments | sample autocovariances |
| exact Gaussian ML | models stationary distribution of the full vector | determinant and quadratic form |
Repeat with n <- 500. Differences usually shrink, illustrating asymptotic agreement without pretending finite-sample identity.
Numerical discipline
Do not write code that evaluates
det(Sigma)
solve(Sigma)
inside an optimiser. Determinants can underflow or overflow, and a full inverse performs unnecessary work. Use
U <- chol(Sigma)
logdet <- 2 * sum(log(diag(U)))
z <- backsolve(U, x, transpose = TRUE)
quadratic <- sum(z^2)
The code then mirrors the mathematics and exposes failure when is not positive definite.
Exercises
- Predict for state by the AR(2) recursion and compare with the cell.
- Remove from the predictor vector. Why does the MSPE remain unchanged under the true AR(2)?
- Set and repeat the estimator comparison. Record convergence, condition number, and estimate dispersion across seeds.
- Add an unknown mean to the likelihood and replace by . Which parameter correlations do you expect?
- Graduate extension: use the delta method to transform the Hessian covariance from to .
Checkpoints
- ; the third coordinate has no direct coefficient.
- The Markov state already consists of ; the older value adds no linear information conditional on that state.
- Near the boundary, covariance matrices become ill-conditioned and normal approximations become less reliable.
- The mean and persistence can be strongly confounded in short, persistent series.
- Multiply the eta-scale variance by at the estimate.
Completion standard
You should be able to identify the covariance block used for prediction, verify its normal equations, and explain why conditional, moment, and exact likelihood estimates differ in finite samples.
Continue to Lab 4 — State Space.
R Matrix Lab 2 — AR Recursions and Yule–Walker Equations
Convert AR models to companion form, compare polynomial roots with eigenvalues, propagate shocks, and recover coefficients from autocovariances.
R Matrix Lab 4 — State Space and Kalman Filtering
Implement Kalman prediction and correction from matrix equations, handle missing observations, and express AR forecasts as state propagation.