Skip to content

Commit e5fa78e

Browse files
sbfnkclaude
andcommitted
Further increase data length for seasonal models to 240 points
STL models appear to need more than 10 seasonal cycles. Increased all seasonal model examples from 120 to 240 data points (20 years of monthly data) to ensure sufficient cycles for fitting. Updated in both forecast-models.Rmd and forecastbaselines.Rmd. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f7bea93 commit e5fa78e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

vignettes/forecast-models.Rmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ historical periods.
301301
```{r lsd}
302302
# Monthly data with seasonality
303303
set.seed(123)
304-
months <- 1:120
304+
months <- 1:240
305305
seasonal_pattern <- 20 + 10 * sin(2 * pi * months / 12)
306-
data <- seasonal_pattern + rnorm(120, sd = 2)
306+
data <- seasonal_pattern + rnorm(240, sd = 2)
307307
308308
# Fit LSD model
309309
model <- LSDModel(window_width = 3, s = 12) # Average last 3 years
@@ -314,10 +314,10 @@ fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:12)
314314
315315
# Plot
316316
plot(data,
317-
type = "l", xlim = c(1, 132),
317+
type = "l", xlim = c(1, 252),
318318
main = "LSD Model: Seasonal Forecast"
319319
)
320-
lines(121:132, fc$mean, col = "red", lwd = 2)
320+
lines(241:252, fc$mean, col = "red", lwd = 2)
321321
```
322322

323323
**Parameter Guidance:**
@@ -531,10 +531,10 @@ where $T_t$ is trend, $S_t$ is seasonal, $R_t$ is remainder.
531531
```{r stl}
532532
# Generate trend + seasonality
533533
set.seed(123)
534-
time <- 1:120 # 10 years of monthly data
534+
time <- 1:240 # 20 years of monthly data
535535
trend <- 0.5 * time
536536
seasonal <- 10 * sin(2 * pi * time / 12)
537-
data <- 50 + trend + seasonal + rnorm(120, sd = 2)
537+
data <- 50 + trend + seasonal + rnorm(240, sd = 2)
538538
539539
# Fit STL model
540540
model <- STLModel(s = 12)
@@ -545,11 +545,11 @@ fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:12)
545545
546546
# Plot
547547
plot(data,
548-
type = "l", xlim = c(1, 132),
548+
type = "l", xlim = c(1, 252),
549549
main = "STL Model: Trend + Seasonality",
550550
ylab = "Value"
551551
)
552-
lines(121:132, fc$mean, col = "red", lwd = 2)
552+
lines(241:252, fc$mean, col = "red", lwd = 2)
553553
```
554554

555555
**Parameter Guidance:**
@@ -884,10 +884,10 @@ lines(73:84, fc$mean, col = "red", lwd = 2)
884884
```{r sales-example}
885885
# Simulated retail sales: trend + seasonality + promotions
886886
set.seed(123)
887-
months <- 1:120
887+
months <- 1:240
888888
trend <- 1000 + 20 * months
889889
seasonal <- 200 * sin(2 * pi * months / 12) # Holiday peaks
890-
noise <- rnorm(120, sd = 50)
890+
noise <- rnorm(240, sd = 50)
891891
data <- trend + seasonal + noise
892892
893893
# Try multiple models

vignettes/forecastbaselines.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ For data with strong seasonal patterns, use seasonal models:
320320
```{r seasonal}
321321
# Generate seasonal data (monthly, s=12)
322322
set.seed(789)
323-
seasonal_data <- 10 + 5 * sin(2 * pi * (1:120) / 12) + rnorm(120)
323+
seasonal_data <- 10 + 5 * sin(2 * pi * (1:240) / 12) + rnorm(240)
324324
325325
# STL decomposition model
326326
stl_model <- STLModel(s = 12)

0 commit comments

Comments
 (0)