R Matrix Laboratory

R Matrix Lab 3 — Prediction and Gaussian Likelihood

Solve best-linear-prediction equations, verify Schur-complement uncertainty, and compare conditional, moment, and exact Gaussian AR estimates.

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 X\mathbf X and target be YY. Partition their joint covariance:

Var(XY)=[ΓggγY].\operatorname{Var} \begin{pmatrix}\mathbf X\\Y\end{pmatrix} = \begin{bmatrix} \Gamma&\mathbf g\\ \mathbf g^\top&\gamma_Y \end{bmatrix}.

Then

Y^=aX,Γa=g,\widehat Y=\mathbf a^\top\mathbf X,\qquad \Gamma\mathbf a=\mathbf g,

and

Var(YY^)=γYgΓ1g.\operatorname{Var}(Y-\widehat Y) =\gamma_Y-\mathbf g^\top\Gamma^{-1}\mathbf g.

Example 1 — Predictor weights and Schur complement

Use an AR(2) with ϕ=(0.65,0.20)\phi=(0.65,-0.20)^\top and innovation variance 1.5. Predict Xt+1X_{t+1} from

X=(Xt,Xt1,Xt2).\mathbf X=(X_t,X_{t-1},X_{t-2})^\top.

The model says that only the first two coordinates should retain non-zero weights.

R

Solve and audit the best linear predictor

Idle

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):

Xt=ϕXt1+εt.X_t=\phi X_{t-1}+\varepsilon_t.

Compare:

ϕ^CLS=t=2nxtxt1t=2nxt12,ϕ^YW=γ^(1)γ^(0),\widehat\phi_{CLS} =\frac{\sum_{t=2}^n x_tx_{t-1}} {\sum_{t=2}^n x_{t-1}^2}, \qquad \widehat\phi_{YW} =\frac{\widehat\gamma(1)}{\widehat\gamma(0)},

and the exact Gaussian maximum-likelihood estimate based on

Σ(ϕ,σ2)=σ21ϕ2Toeplitz(1,ϕ,,ϕn1).\Sigma(\phi,\sigma^2) =\frac{\sigma^2}{1-\phi^2} \operatorname{Toeplitz}(1,\phi,\ldots,\phi^{n-1}).
R

Compare conditional, Yule-Walker, and exact Gaussian estimates

Idle

The estimates are not expected to match exactly:

EstimatorInitial-condition treatmentMain sample summary
conditional LSconditions on x1x_1transition residual sum of squares
Yule–Walkerreplaces population momentssample autocovariances
exact Gaussian MLmodels stationary distribution of the full vectordeterminant 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 Σ\Sigma is not positive definite.

Exercises

  1. Predict Xt+1X_{t+1} for state (1.2,0.4,0.5)(1.2,0.4,-0.5)^\top by the AR(2) recursion and compare with the cell.
  2. Remove Xt2X_{t-2} from the predictor vector. Why does the MSPE remain unchanged under the true AR(2)?
  3. Set ϕtrue=0.95\phi_{\text{true}}=0.95 and repeat the estimator comparison. Record convergence, condition number, and estimate dispersion across seeds.
  4. Add an unknown mean μ\mu to the likelihood and replace x\mathbf x by xμ1\mathbf x-\mu\mathbf1. Which parameter correlations do you expect?
  5. Graduate extension: use the delta method to transform the Hessian covariance from η1=atanh(ϕ)\eta_1=\operatorname{atanh}(\phi) to ϕ\phi.
Checkpoints
  1. 0.65(1.2)0.20(0.4)=0.700.65(1.2)-0.20(0.4)=0.70; the third coordinate has no direct coefficient.
  2. The Markov state already consists of (Xt,Xt1)(X_t,X_{t-1}); the older value adds no linear information conditional on that state.
  3. Near the boundary, covariance matrices become ill-conditioned and normal approximations become less reliable.
  4. The mean and persistence can be strongly confounded in short, persistent series.
  5. Multiply the eta-scale variance by (1ϕ2)2(1-\phi^2)^2 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.

Copyright © 2026