R Matrix Laboratory
R Matrix Laboratory — Theory You Can Execute
Laboratory purpose
These laboratories translate classical time-series derivations into base R. They do not begin with a large empirical dataset or automated model selection. Each starts from a mathematical object whose answer is known well enough to check.
Every code cell is:
- self-contained and runnable in the browser with webR;
- written with base R and the recommended
statspackage; - explicit about dimensions and parameter conventions;
- followed by a numerical identity or error check.
Lab map
| Lab | Central equation | Main R tools | Output |
|---|---|---|---|
| 1. Covariance geometry | toeplitz, eigen, chol | valid finite covariance block | |
| 2. AR recursions | polyroot, eigen, ARMAacf | roots, impulse responses, Yule–Walker solution | |
| 3. Prediction and likelihood | and | solve, chol, optim | predictor plus exact Gaussian estimate |
| 4. State space | Kalman prediction and correction | %*%, kronecker, loops | filtered states and forecast covariance |
Working conventions
- Vectors in the notes are columns. R vectors acquire column meaning when used with
%*%. chol(Sigma)returns an upper-triangular satisfying .ARMAacffollows R's model convention .matrix(v, nrow=k)fills by columns, matching the usual operator.- Use
solve(A, b)for ; reservesolve(A)for occasions when the full inverse is genuinely needed.
How to submit a lab
For each cell, report four items:
Equation:
Dimensions:
Numerical check:
One-parameter perturbation and predicted effect:
“The output looks right” is not a check. Examples of checks are
Workload
Each lab is designed for 45–60 minutes:
- 10 minutes: reproduce one derivation by hand;
- 15 minutes: run and annotate the original cells;
- 15 minutes: make one controlled parameter change;
- 10–20 minutes: answer the exercises and write the mathematical conclusion.
Start
Open Lab 1. Before running code, predict what happens to the smallest eigenvalue and condition number when an AR(1) coefficient moves from to .
Module 6 — Spectral Analysis, Cycles, and Filters
Translate autocovariance into frequency, estimate spectra, diagnose cycles, and avoid aliasing and filtering leakage.
R Matrix Lab 1 — Covariance Geometry
Construct stationary Toeplitz covariance matrices, test positive definiteness, factor them, and simulate Gaussian finite blocks.