توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
درس 10 از 22
Represent ordered data correctly and separate levels, changes, trend, seasonality, and remainder.
Motivation
Time adds order and dependence. Treating monthly observations as an unordered sample discards information needed for forecasting and uncertainty.
Why this matters
Represent ordered data correctly and separate levels, changes, trend, seasonality, and remainder.
Packages and data
Base stats; tsibble, fable, and feasts are optional modern extensions.
توضیح 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.
اصطلاحات
Observations per seasonal cycle; metadata, not proof of complete dates.
12 for monthly data
A rising price level can coexist with falling inflation.
State horizon and denominator
Future information entering a feature used at an earlier forecast origin.
Centred smoothers can leak
نمادگذاری و فرمولها
yt = trend_t + seasonal_t + remainder_t
STL components depend on smoothing choices and are not uniquely observed causal quantities.
مثال حلشده
سناریو
Can a regular monthly series be decomposed into trend, seasonality, and remainder?
بررسی با R
set.seed(1010)
t <- 1:60
x <- ts(100 + 0.3*t + 2*sin(2*pi*t/12) + rnorm(60,0,0.5), frequency=12, start=c(2021,1))
fit <- stl(x, s.window='periodic', robust=TRUE)
print(frequency(x))
print(sd(fit$time.series[,'remainder']))
plot(fit)The periodic seasonal pattern repeats by month while trend rises; remainder captures what this decomposition leaves. Limitation: Full-sample decomposition is descriptive and uses future values near earlier dates; forecast evaluation must refit on training data.
Visual
A simulated monthly series combines a rising trend and repeating seasonal movement.
ارتباط با 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 time-series objects, trend, and decomposition.
Ready to run
Common mistake
Do not infer regular monthly spacing from row count alone.
STATLAB Tip
Plot both the level and a substantively meaningful change.
تمرین هدایتشده
سناریو
Aggregate monthly values to quarters using both averages and final-month levels; explain the different questions.
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
Compute first and lag-12 differences.
توضیح 2
Compare annual average with December level.
توضیح 3
Change the STL seasonal window.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
توضیح 1
diff(x); diff(x,lag=12)
توضیح 2
aggregate(x,nfrequency=1,FUN=mean)
توضیح 3
Refit and compare endpoint components; they are smoothing-dependent.
Chapter summary
Represent ordered data correctly and separate levels, changes, trend, seasonality, and remainder.
توضیح 1
Validate the time index.
توضیح 2
Levels and changes answer different questions.
توضیح 3
STL is model-dependent.
توضیح 4
Prevent future information leakage.
اصطلاحات
regular series
Use in Time-Series Objects, Trend, and Decomposition.
seasonal frequency
Use in Time-Series Objects, Trend, and Decomposition.
change
Use in Time-Series Objects, Trend, and Decomposition.
decomposition
Use in Time-Series Objects, Trend, and Decomposition.
References and provenance
Safavi (2026), Chapter 10; Statistics Canada (2026). 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.
ارزیابی پایانی