توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
درس 13 از 22
Combine calendar structure and predictors with time-series errors while respecting future availability.
Motivation
Ordinary regression standard errors fail when errors remain autocorrelated; dynamic regression models the mean and serial dependence together.
Why this matters
Combine calendar structure and predictors with time-series errors while respecting future availability.
Packages and data
Base stats; forecast/fable optional.
توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
توضیح 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
توضیح 3
R code, paths, function names, and formulas remain left-to-right in every locale.
اصطلاحات
Current value minus the same seasonal position one cycle earlier.
yt - y(t-12)
Smooth sine/cosine seasonal basis.
Parsimonious calendar pattern
Pulse, step, or ramp encoding a known event.
Not automatically causal
نمادگذاری و فرمولها
yt = beta0 + beta' xt + nt, where nt follows ARIMA
Predictor coefficients describe the conditional mean while the error model handles remaining dependence.
مثال حلشده
سناریو
How can monthly seasonality be encoded without twelve separate parameters?
بررسی با R
t <- 1:60; s <- 12
fourier <- cbind(sin1=sin(2*pi*t/s), cos1=cos(2*pi*t/s), sin2=sin(4*pi*t/s), cos2=cos(4*pi*t/s))
y <- 2 + .03*t + 1.2*fourier[,1] + .6*fourier[,2]
fit <- lm(y ~ t + fourier)
print(coef(fit))
print(Box.test(residuals(fit),lag=12,type='Ljung-Box'))Calendar terms are known in advance, so they can support forecasts without requiring an external predictor scenario. Limitation: Policy and exchange-rate futures are not known; using realized future values would be leakage.
Visual
Illustrative monthly index repeats a smooth annual pattern.
ارتباط با R
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for seasonality and dynamic regression.
Ready to run
Common mistake
A lag establishes timing, not exogeneity or causation.
STATLAB Tip
Draw a timeline of when every predictor becomes available relative to the forecast origin.
تمرین هدایتشده
سناریو
Fit monthly indicator effects and compare residual ACF with the Fourier model.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
توضیح 1
Create December pulse and post-2020 step variables.
توضیح 2
Generate two harmonic pairs.
توضیح 3
Define two future predictor scenarios.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
توضیح 1
december <- as.integer(month==12); post <- as.integer(date>=as.Date('2020-03-01'))
توضیح 2
Use sin(2*pi*k*t/12) and cos(...) for k=1,2.
توضیح 3
State both the assumed path and how forecast uncertainty depends on it.
Chapter summary
Combine calendar structure and predictors with time-series errors while respecting future availability.
توضیح 1
Seasonality can be deterministic or stochastic.
توضیح 2
Indicators and Fourier terms impose different structures.
توضیح 3
ARIMA errors repair serial-dependence inference.
توضیح 4
Future predictor availability governs forecasting.
اصطلاحات
seasonal change
Use in Seasonality and Dynamic Regression.
indicators
Use in Seasonality and Dynamic Regression.
Fourier terms
Use in Seasonality and Dynamic Regression.
distributed lag
Use in Seasonality and Dynamic Regression.
References and provenance
Safavi (2026), Chapter 13. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
منبع
The authoritative 125-page English PDF accompanies this native lesson.
دریافتبازاندیشی
Name the assumption, evidence you would seek, and how the recommendation might change.
ارزیابی پایانی