Skip to content

Commit f7bea93

Browse files
sbfnkclaude
andcommitted
Increase data length for seasonal model examples to meet minimum requirements
STL and LSD models require sufficient seasonal cycles in the data. Increased from 60 to 120 data points (5 to 10 years of monthly data) to ensure models have enough cycles to fit properly. Changes: - STLModel examples: 72 → 120 points - LSDModel examples: 60 → 120 points - Updated plot ranges to match new data lengths This fixes the error: "Time series needs at least `ns` seasonal cycles" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e8268da commit f7bea93

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:60
304+
months <- 1:120
305305
seasonal_pattern <- 20 + 10 * sin(2 * pi * months / 12)
306-
data <- seasonal_pattern + rnorm(60, sd = 2)
306+
data <- seasonal_pattern + rnorm(120, 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, 72),
317+
type = "l", xlim = c(1, 132),
318318
main = "LSD Model: Seasonal Forecast"
319319
)
320-
lines(61:72, fc$mean, col = "red", lwd = 2)
320+
lines(121:132, 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:72 # 6 years of monthly data
534+
time <- 1:120 # 10 years of monthly data
535535
trend <- 0.5 * time
536536
seasonal <- 10 * sin(2 * pi * time / 12)
537-
data <- 50 + trend + seasonal + rnorm(72, sd = 2)
537+
data <- 50 + trend + seasonal + rnorm(120, 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, 84),
548+
type = "l", xlim = c(1, 132),
549549
main = "STL Model: Trend + Seasonality",
550550
ylab = "Value"
551551
)
552-
lines(73:84, fc$mean, col = "red", lwd = 2)
552+
lines(121:132, 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:60
887+
months <- 1:120
888888
trend <- 1000 + 20 * months
889889
seasonal <- 200 * sin(2 * pi * months / 12) # Holiday peaks
890-
noise <- rnorm(60, sd = 50)
890+
noise <- rnorm(120, 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:60) / 12) + rnorm(60)
323+
seasonal_data <- 10 + 5 * sin(2 * pi * (1:120) / 12) + rnorm(120)
324324
325325
# STL decomposition model
326326
stl_model <- STLModel(s = 12)

0 commit comments

Comments
 (0)