class: center, middle, inverse, title-slide .title[ # CSSS/POLS 512 ] .subtitle[ ## Lab 3: Modeling Stationary Time Series — Estimation, Selection, and Cross-Validation ] .author[ ### Ramses Llobet ] .date[ ### Spring 2026 ] --- # Today's Plan .pull-left[ **Part 1: The applied example + diagnostics** - UK road deaths & the 1983 seatbelt law - Diagnostic workflow (quick review) **Part 2: Estimating ARMA with covariates** - `arima()` + `xreg` refresher - **Impact effect vs. long-run equilibrium** - Visualizing the dynamic response ] .pull-right[ **Part 3: Model selection** - AIC / BIC / MSE (brief) - The full 11-candidate grid **Part 4: Cross-validation** - Why standard CV fails for time series - Expanding vs. sliding windows - Full CV grid + best model **Part 5: Predicted values & intervals** ] --- class: inverse, center, middle # Part 1: The Case Study --- # UK Road Deaths and the 1983 Seatbelt Law <img src="Lab3_slides_files/figure-html/deaths-plot-1.svg" width="864" style="display: block; margin: auto;" /> -- **Research question:** How large was the effect of the seatbelt law on road deaths, accounting for **seasonality** and **autoregressive dynamics**? --- # Diagnostic Workflow (Review from Lab 2) Before estimation, apply the Box-Jenkins workflow: .pull-left[ **1. Plot** the series — visible trend, seasonality, level shifts? **2. STL decomposition** — separate trend + seasonal + remainder. **3. ACF/PACF** on the raw series — identify candidate AR/MA structure. **4. Clean the series** — `lm()` on trend + month dummies + law — and re-examine the ACF/PACF of the residuals. ] .pull-right[ **What we find for UK deaths:** - Strong **seasonal cycle** at lag 12 - **Trend** + policy shift at 1983 - After cleaning: ACF tails off, PACF significant at lags 1 and 2 - → **AR(1) or AR(2)** on the residual dynamics ] -- **Strategy:** combine the covariates (law + month dummies) with an ARMA error structure in a **single joint model** via `arima()` with `xreg`. .footnote[*Code: `Lab3.Rmd` → Sections 1.1–1.2*] --- class: inverse, center, middle # Part 2: ARMA with Covariates --- # Regression with ARMA Errors `$$y_t = \underbrace{\boldsymbol{x}_t \boldsymbol{\beta}}_{\text{covariates}} + \underbrace{\eta_t}_{\text{ARMA errors}}$$` -- In R: ```r Arima(deaths, order = c(2, 0, 0), xreg = cbind(law, month_dummies)) ``` `arima()` estimates `\(\boldsymbol{\beta}\)` and the ARMA parameters **jointly by MLE**. OLS with a lagged DV would be biased; `arima()` handles the serial correlation correctly. -- **The key interpretive challenge:** the coefficient on `law` is the *immediate* effect. But AR persistence means the effect **propagates** through time before the series settles. .footnote[*Code: `Lab3.Rmd` → Sections 2.1–2.4*] --- # Impact Effect vs. Long-Run Equilibrium For **AR(`\(p\)`)** errors, the equilibrium mean of the series is: `$$\mathbb{E}(y_t) = \frac{\boldsymbol{x}_t \boldsymbol{\beta}}{1 - \sum_{k=1}^{p} \phi_k} \qquad\Longrightarrow\qquad \text{Long-run effect} = \frac{\hat{\beta}}{1 - \sum_{k=1}^{p} \hat{\phi}_k}$$` -- .pull-left[ **Two quantities that matter:** - **Impact** `\(= \hat{\beta}\)` (first-period change) - **Long-run** `\(= \hat{\beta} \cdot \frac{1}{1 - \sum\hat{\phi}_k}\)` (final equilibrium shift) ] .pull-right[ **For UK deaths AR(2)** (`\(\hat{\phi}_1 \approx 0.47\)`, `\(\hat{\phi}_2 \approx 0.27\)`): - Impact: `\(\approx -348\)` deaths/month - Multiplier: `\(\approx 3.86\)` - Long-run: `\(\approx -1340\)` deaths/month ] -- The impact is what happens in month 1; the long-run effect is where the series ends up once all dynamics have settled. .footnote[*Code: `Lab3.Rmd` → Section 2.5*] --- # The Dynamic Response to the Seatbelt Law <img src="Lab3_slides_files/figure-html/step-response-slide-1.svg" width="792" style="display: block; margin: auto;" /> Sharp drop at month 1 (impact) → gradual adjustment → new equilibrium. .footnote[*Code: `Lab3.Rmd` → Section 2.5 (step-response + horizon choice)*] --- class: inverse, center, middle # Part 3: Model Selection --- # Goodness of Fit: AIC, BIC, MSE | Metric | What it rewards | Penalty | |:-------|:----------------|:--------| | **AIC** | Likelihood fit | `\(+2k\)` per parameter | | **BIC** | Likelihood fit | `\(+k\ln n\)` (heavier) | | **MSE** | Raw fit | **none** — always favors bigger models | -- **Key facts:** - For models fit by **MLE** (like `arima()`), AIC/BIC are the natural criteria — same likelihood the estimator already maximized - For normal regression: `\(\text{AIC} = n\ln(\text{MSE}) + 2k + C\)` (constant drops out in comparisons) - AIC favors predictive accuracy; BIC favors parsimony - When they disagree → prefer the simpler model (Occam's razor) -- **Practical workflow:** fit a grid of candidates, compare AIC + residual diagnostics (Ljung-Box, Jarque-Bera), pick the most parsimonious model whose residuals pass. .footnote[*Code: `Lab3.Rmd` → Sections 3.1–3.3*] --- class: inverse, center, middle # Part 4: Cross-Validation --- # Why Standard CV Fails for Time Series In cross-sectional data, we randomly split into train/test sets. But in time series, **we cannot predict the past from the future** — random splits break the temporal ordering. -- ### Standard hold-out CV <img src="images/holdoutcv.jpeg" width="55%" style="display: block; margin: auto;" /> Random train/test split → breaks the time order. --- # `\(k\)`-fold CV <img src="images/kfoldcv.png" width="55%" style="display: block; margin: auto;" /> Shuffling observations into folds still violates temporal ordering. **What we need instead:** a scheme where training always comes **before** testing. --- # Expanding Window <img src="Lab3_slides_files/figure-html/expand-window-1.svg" width="864" style="display: block; margin: auto;" /> Training set grows as we move forward; test set is always after the training set. --- # Sliding (Rolling) Window <img src="Lab3_slides_files/figure-html/slide-window-1.svg" width="864" style="display: block; margin: auto;" /> Fixed-length training window; useful when the process may change over time. .footnote[*Code: `Lab3.Rmd` → Section 4.2–4.3 (manual loop) and 4.4 (`tsCV()`)*] --- # Full CV Grid: 11 Candidate Models <img src="Lab3_slides_files/figure-html/cv-grid-slide-1.svg" width="864" style="display: block; margin: auto;" /> .footnote[*Code: `Lab3.Rmd` → Section 4.4*] --- class: inverse, center, middle # Part 5: Predicted Values & Intervals --- # Forecasting with `forecast()` <img src="Lab3_slides_files/figure-html/forecast-plot-slide-1.svg" width="864" style="display: block; margin: auto;" /> Point forecast + prediction intervals grow with horizon to reflect accumulating uncertainty. .footnote[*Code: `Lab3.Rmd` → Section 5.1–5.3 (single forecast) and 5.4 (two-scenario comparison)*] --- # Wrap-Up **Today we covered:** - ARMA estimation with covariates via `Arima()` + `xreg` (MLE, not OLS) - Interpreting dynamics: **impact vs. long-run equilibrium** (AR(1) → AR(p)) - Model selection: AIC/BIC (MLE natural) + residual diagnostics - Time series cross-validation: sliding/expanding windows, manual loop + `tsCV()` - Forecasting with `xreg`: point forecasts + prediction intervals -- **Coming up next (Lab 4):** - Non-stationary time series and ARIMA(p, **d**, q) - **Counterfactual forecasting** with parametric simulation - **Interrupted time series (ITS)** for causal inference -- **Self-study:** - Box-Steffensmeier et al. (2014), Ch. 2.4–2.5 - Hyndman & Athanasopoulos, [FPP3 Ch. 5](https://otexts.com/fpp3/toolbox.html) (time series CV) --- class: inverse, center, middle # Questions?