Optional Python Lab 1 — Explore Before Modeling
Optional Python Lab 1 — Explore Before Modeling
Question
Which structures are visible, and which apparent autocorrelation may disappear after they are modeled?
Predict before running
The mechanism contains trend, fixed seasonality, a step at observation 49, and AR(1) errors. Sketch the expected time plot and ACF first. Then compare your sketch with the output.
Generate and explore monthly demand
Read the evidence
| Panel | What it shows | What it cannot decide alone |
|---|---|---|
| time plot | timing of trend, month pattern, and break | deterministic versus stochastic trend |
| month boxes | stable seasonal position differences | seasonal ARIMA order |
| lag plot | strong adjacent association in levels | whether association survives adjustment |
| level ACF | mixed persistence and seasonal peaks | residual AR order |
The raw ACF is deliberately confounded. Choosing AR lags from it before addressing trend, seasonality, and the intervention would attribute mean structure to stochastic feedback.
Evidence log
Index frequency and missing timestamps:
Mean structure:
Variance structure:
Seasonal evidence:
Intervention/break evidence:
Dependence to inspect after adjustment:
Benchmark for 12-month forecasts:
Perturbations
- Set the AR coefficient to
0: trend and seasonality still produce a persistent raw ACF. - Set the intervention size to
0: the 2023 step disappears. - Set the random seed to
9: the mechanism is unchanged, but finite-sample details move. - Use only the first 36 observations: explain why stable diagnosis becomes harder.
Continue to Python Lab 2.
Optional Python Appendix — Empirical Forecasting
A supplementary Pyodide forecasting workflow for students who want to contrast matrix theory with an applied software pipeline.
Optional Python Lab 2 — Diagnose Stationarity
Compare ADF/KPSS evidence for differencing with a mechanism-aligned deterministic adjustment.