R Matrix Laboratory

R Matrix Lab 1 — Covariance Geometry

Construct stationary Toeplitz covariance matrices, test positive definiteness, factor them, and simulate Gaussian finite blocks.

R Matrix Lab 1 — Covariance Geometry

Question

How can a proposed autocovariance sequence become a valid finite-dimensional distribution?

For a weakly stationary process,

Γn=[γ(ij)]i,j=1n.\Gamma_n=[\gamma(i-j)]_{i,j=1}^n.

The matrix must be symmetric and positive semidefinite because, for every a\mathbf a,

Var(aXn)=aΓna0.\operatorname{Var}(\mathbf a^\top\mathbf X_n) =\mathbf a^\top\Gamma_n\mathbf a\ge0.

Example 1 — AR(1) Toeplitz structure

For

Xt=ϕXt1+εt,Var(εt)=σε2,X_t=\phi X_{t-1}+\varepsilon_t,\qquad \operatorname{Var}(\varepsilon_t)=\sigma_\varepsilon^2,

stationarity requires ϕ<1|\phi|<1 and

γ(h)=σε21ϕ2ϕh.\gamma(h)=\frac{\sigma_\varepsilon^2}{1-\phi^2}\phi^{|h|}.

The first column of Γ6\Gamma_6 is therefore

γ(0)(1,ϕ,ϕ2,,ϕ5).\gamma(0)(1,\phi,\phi^2,\ldots,\phi^5)^\top.
R

Build and audit an AR(1) covariance matrix

Idle

Read the output

  • Equal diagonals confirm Toeplitz structure.
  • Positive eigenvalues establish positive definiteness for this finite block.
  • The Cholesky error checks the factorisation numerically.
  • The quadratic-form check connects a matrix calculation to a familiar variance.

Change ϕ\phi to 0.6-0.6. The first off-diagonal changes sign, but the matrix remains positive definite. Change it to 0.950.95: the process is still stationary, but the condition number rises because neighbouring variables become nearly redundant.

Example 2 — Gaussian simulation by a matrix square root

Let zN(0,In)\mathbf z\sim N(\mathbf0,I_n) and choose LL with LL=ΓnLL^\top=\Gamma_n. Then

Xn=μ+Lz\mathbf X_n=\boldsymbol\mu+L\mathbf z

has mean μ\boldsymbol\mu and covariance Γn\Gamma_n.

R returns U=chol(Γn)U=\operatorname{chol}(\Gamma_n) with UU=ΓnU^\top U=\Gamma_n, so use L=UL=U^\top.

R

Simulate Gaussian blocks with a Cholesky factor

Idle

The empirical error will not be exactly zero because only finitely many blocks were simulated. Increase replications by a factor of four: Monte Carlo error should shrink by roughly a factor of two.

Why pairwise correlations are not enough

Values satisfying ρ(h)1|\rho(h)|\le1 do not automatically form a valid autocorrelation sequence. All finite Toeplitz blocks must be positive semidefinite. A proposed sequence can pass every pairwise bound and still produce a negative eigenvalue.

This is the matrix reason that an ACF cannot be invented one lag at a time.

Exercises

  1. With ϕ=0.6\phi=0.6 and innovation variance 2, calculate γ(0)\gamma(0) and γ(1)\gamma(1) by hand.
  2. Replace gamma by c(1, 0.9, -0.9) and inspect the eigenvalues of toeplitz(gamma). Is it a valid three-lag covariance block?
  3. Show algebraically that Var(XtXt1)=2[γ(0)γ(1)]\operatorname{Var}(X_t-X_{t-1})=2[\gamma(0)-\gamma(1)].
  4. Compare the condition numbers for ϕ=0\phi=0, 0.60.6, 0.90.9, and 0.990.99. Explain the statistical meaning.
  5. Graduate extension: prove that every principal submatrix of a positive semidefinite matrix is positive semidefinite.
Checkpoints
  1. γ(0)=2/(10.36)=3.125\gamma(0)=2/(1-0.36)=3.125 and γ(1)=1.875\gamma(1)=1.875.
  2. It has a negative eigenvalue, so satisfying the individual bounds ρ(h)1|\rho(h)|\le1 was insufficient.
  3. Expand Var(Xt)+Var(Xt1)2Cov(Xt,Xt1)\operatorname{Var}(X_t)+\operatorname{Var}(X_{t-1})-2\operatorname{Cov}(X_t,X_{t-1}).
  4. Near one, adjacent coordinates are almost collinear; separating long-run level variation from persistence becomes numerically and statistically difficult.

Completion standard

You should be able to build Γn\Gamma_n from γ(0),,γ(n1)\gamma(0),\ldots,\gamma(n-1), justify positive semidefiniteness with quadratic forms, and use Cholesky reconstruction as a reproducible numerical check.

Continue to Lab 2 — AR Recursions.

Copyright © 2026