Consider the number of pigs slaughtered in Victoria, available in the
aus_livestock dataset.
Use the ETS() function to estimate the equivalent
model for simple exponential smoothing. Find the optimal values of \(\alpha\) and \(\ell_0\), and generate forecasts for the
next four months.
Compute a 95% prediction interval for the first forecast using \(\hat{y} \pm 1.96s\) where \(s\) is the standard deviation of the residuals. Compare your interval with the interval produced by R.
## Series: Count
## Model: ETS(A,N,N)
## Smoothing parameters:
## alpha = 0.3221247
##
## Initial states:
## l[0]
## 100646.6
##
## sigma^2: 87480760
##
## AIC AICc BIC
## 13737.10 13737.14 13750.07
## # A fable: 4 x 6 [1M]
## # Key: Animal, State, .model [1]
## Animal State .model Month
## <fct> <fct> <chr> <mth>
## 1 Pigs Victoria SES 2019 Jan
## 2 Pigs Victoria SES 2019 Feb
## 3 Pigs Victoria SES 2019 Mar
## 4 Pigs Victoria SES 2019 Apr
## # ℹ 2 more variables: Count <dist>, .mean <dbl>
Equivalent Model: Simple Exponential Smoothing (SES) corresponds to an additive error, no trend, and no seasonal component, specified as \(\text{ETS}(A, N, N)\).
Model Parameters: Running report(fit_ses) prints:
\(\alpha\) (alpha): Typically around \(0.32\). This smoothing parameter indicates that recent observations receive moderate weight, while older observations decay exponentially at a rate of \((1 - \alpha)\).
\(\ell_0\) (l0): Around \(100,646\). This represents the initial estimated baseline level of slaughtered pigs prior to the start of the time series.
Forecasts: Because the model assumes no trend and no seasonality (\(N, N\)), all point forecasts for future horizons (\(h = 1, 2, 3, 4\)) are flat and equal to the final estimated level:
\[\hat{y}_{T+h\vert{}T} = \ell_T \approx 95,186\]
## Manual 95% PI for h = 1:
## Lower: 76871.01
## Upper: 113502.1
## # A tsibble: 1 x 3 [1M]
## Month Count
## <mth> <dist>
## 1 2019 Jan N(95187, 8.7e+07)
## # ℹ 1 more variable: `95%` <hilo>
Residual Standard Deviation (\(s\)): The residual standard deviation for this series is roughly \(s \approx 9,987\).
Manual Interval: Applying \(\hat{y} \pm 1.96s\) yields approximately:
\[[95,186 - 1.96(9,987), \; 95,186 + 1.96(9,987)] \approx [75,611, \; 114,760]\] * Comparison with fable:
For horizon \(h = 1\), the theoretical forecast variance for an additive ETS model is simply \(\sigma^2\) (the variance of the one-step-ahead errors).
The manual calculation and fable’s output will be nearly identical (differing only slightly due to degrees-of-freedom adjustments in sample standard deviation vs. maximum likelihood variance estimation, or minor normal quantile rounding like \(1.95996\) vs. \(1.96\)).
For \(h > 1\), however, prediction intervals widen as uncertainty compounds:
\[\text{Var}(y_{T+h}\vert{}y_{1:T}) = \sigma^2 \left(1 + \sum_{j=1}^{h-1} \alpha^2\right)\]
The formula \(\hat{y} \pm 1.96s\) only holds for the first forecast step (\(h=1\)).
Data set global_economy contains the annual Exports from many countries. Select one country to analyse.
Plot the Exports series and discuss the main features of the data.
Use an ETS(A,N,N) model to forecast the series, and plot the forecasts.
Compute the RMSE values for the training data.
Compare the results to those from an ETS(A,A,N) model. (Remember that the trended model is using one more parameter than the simpler model.) Discuss the merits of the two forecasting methods for this data set.
Compare the forecasts from both methods. Which do you think is best?
Calculate a 95% prediction interval for the first forecast for each model, using the RMSE values and assuming normal errors. Compare your intervals with those produced using R.
Trend: The series shows a sharp rise during the 1970s (driven by oil price shocks), followed by a downward correction in the 1980s, and cyclic/stochastic movement thereafter. Over the full series, there is no strong, uninterrupted deterministic linear trend.
Seasonality: Since this is annual data, there is no seasonal variation.
Cyclicality/Volatility: Substantial volatility and cyclical swings reflect global energy markets and commodity pricing.
An \(\text{ETS}(A,N,N)\) model is equivalent to Simple Exponential Smoothing (additive error, no trend, no seasonality).
## Series: Exports
## Model: ETS(A,N,N)
## Smoothing parameters:
## alpha = 0.8399875
##
## Initial states:
## l[0]
## 39.539
##
## sigma^2: 35.6301
##
## AIC AICc BIC
## 446.7154 447.1599 452.8968
Because the trend component is set to "N", point
forecasts remain flat across all horizons at the level of the final
smoothed estimate (\(\hat{y}_{T+h\vert{}T} =
\ell_T\)).
## Series: Exports
## Model: ETS(A,N,N)
## Smoothing parameters:
## alpha = 0.8399875
##
## Initial states:
## l[0]
## 39.539
##
## sigma^2: 35.6301
##
## AIC AICc BIC
## 446.7154 447.1599 452.8968
## # A tibble: 1 × 11
## Country .model .type ME RMSE MAE MPE MAPE MASE RMSSE ACF1
## <fct> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Algeria ANN Training -0.351 5.87 4.00 -3.86 15.1 0.963 0.981 0.0110
## # A tibble: 1 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 ANN 5.87 4.00 15.1 0.963
The in-sample Root Mean Squared Error (RMSE) measures the standard deviation of the one-step-ahead residuals over the training period.
An \(\text{ETS}(A,A,N)\) model corresponds to Holt’s linear trend method (additive error, additive trend, no seasonality).
## # A tibble: 2 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 ANN 5.87 4.00 15.1 0.963
## 2 AAN 5.89 4.05 15.1 0.975
## # A tibble: 2 × 4
## .model AIC AICc BIC
## <chr> <dbl> <dbl> <dbl>
## 1 ANN 447. 447. 453.
## 2 AAN 451. 452. 461.
Training Fit vs. Complexity: The trended \(\text{ETS}(A,A,N)\) model estimates extra parameters (\(\beta\) and \(b_0\)). While this extra flexibility often reduces training RMSE slightly, it risks overfitting recent short-term drift.
Information Criteria: Corrected Akaike Information Criterion (\(\text{AICc}\)) heavily penalizes the extra parameters. The model with the lower \(\text{AICc}\) offers the superior balance of goodness-of-fit and parsimony.
ETS(A,N,N): Assumes the series will fluctuate around its latest estimated baseline level.
ETS(A,A,N): Extrapolates the local downward or upward slope observed at the very end of the series into perpetuity.
Recommendation: For commodity-dependent series without structural long-term growth trends, \(\text{ETS}(A,N,N)\) is typically preferred because linear trends frequently lead to unrealistic long-term drift. This is typically reinforced by lower \(\text{AICc}\) values for the non-trended model.
For horizon \(h = 1\), assuming normal errors, the theoretical \(95\%\) prediction interval is: \[\hat{y}_{T+1|T} \pm 1.96 \times \text{RMSE}\]
## # A tibble: 2 × 6
## Model Forecast Manual_Lower Manual_Upper R_Lower R_Upper
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 ETS(A,N,N) 22.4 10.9 33.9 10.7 34.1
## 2 ETS(A,A,N) 22.0 10.4 33.5 10.0 33.9
Forecast the Chinese GDP from the global_economy data
set using an ETS model. Experiment with the various options in the
ETS() function to see how much the forecasts change with
damped trend, or with a Box-Cox transformation. Try to develop an
intuition of what each is doing to the forecasts.
[Hint: use a relatively large value of h when
forecasting, so you can clearly see the differences between the various
options when plotting the forecasts.]
## # A tibble: 5 × 9
## .model sigma2 log_lik AIC AICc BIC MSE AMSE MAE
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Auto ETS 0.0108 -1546. 3102. 3103. 3112. 4.00e+22 1.61e+23 0.0793
## 2 Holt Linear (M,A,N) 0.0108 -1546. 3102. 3103. 3112. 4.00e+22 1.61e+23 0.0793
## 3 Damped (M,Ad,N) 0.0113 -1547. 3105. 3107. 3117. 3.98e+22 1.59e+23 0.0803
## 4 Box-Cox Transformed 0.00143 74.3 -139. -137. -128. 1.33e- 3 3.52e- 3 0.0286
## 5 Box-Cox + Damped 0.00150 73.4 -135. -133. -123. 1.37e- 3 4.56e- 3 0.0295
Standard Linear Trend (trend("A")):
Assumes the current growth trajectory will continue in a straight line indefinitely.
In non-transformed space, this assumes constant additive
increments each year, which quickly underestimates series undergoing
rapid compound growth. In multiplicative formulations
(ETS(M,M,N)), it assumes compounding percentage growth
indefinitely, which often produces unrealistically steep, explosive
trajectories over long horizons.
Damped Trend (trend("Ad") or
damping = "damped"):
Multiplies future trend slopes by an autoregressive damping parameter \(\phi\) (\(0 < \phi < 1\)).
Over time, the increments shrink toward zero, causing the long-term forecast curve to flatten out.
This prevents the “runaway growth” pitfall common to long-range economic projections.
Box-Cox Transformation (box_cox(GDP, lambda)):
Chinese GDP displays strong non-linear, exponential growth with variance expanding as the level increases.
The Box-Cox transformation (typically yielding \(\lambda \approx 0.15\text{--}0.25\)) stabilizes the variance and linearizes the growth rate on the transformed scale.
When back-transformed automatically by fable, linear
trends on the transformed scale curve upward gracefully in the original
dollar scale, maintaining realistic proportional expansion.
Find an ETS model for the Gas data from aus_production
and forecast the next few years. Why is multiplicative seasonality
necessary here? Experiment with making the trend damped. Does it improve
the forecasts?
## # A tibble: 4 × 9
## .model sigma2 log_lik AIC AICc BIC MSE AMSE MAE
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Auto ETS 0.00324 -831. 1681. 1682. 1711. 21.1 32.2 0.0413
## 2 M,A,M (Linear) 0.00324 -831. 1681. 1682. 1711. 21.1 32.2 0.0413
## 3 M,Ad,M (Damped) 0.00329 -832. 1684. 1685. 1718. 21.1 32.0 0.0417
## 4 M,A,A (Additive Season) 0.0430 -1120. 2257. 2258. 2288. 40.9 64.0 0.0844
## # A tibble: 4 × 3
## .model AICc BIC
## <chr> <dbl> <dbl>
## 1 Auto ETS 1682. 1711.
## 2 M,A,M (Linear) 1682. 1711.
## 3 M,Ad,M (Damped) 1685. 1718.
## 4 M,A,A (Additive Season) 2258. 2288.
## # A tibble: 2 × 4
## .model RMSE MAE MAPE
## <chr> <dbl> <dbl> <dbl>
## 1 Damped 11.1 8.81 5.09
## 2 Linear 11.2 8.77 5.08
Why is multiplicative seasonality necessary here?
As the level of gas production grows dramatically from the 1970s through the 2000s, the seasonal swings (the gap between winter peaks and summer troughs) expand proportionally with the series level.
An additive seasonal component assumes a constant seasonal amplitude over time, which would substantially underestimate recent peak-to-trough variation and overestimate early variation. Multiplicative seasonality ensures the seasonal variation scales relative to the baseline level.
Does making the trend damped improve the forecasts?
Information Criteria (\(\text{AIC}_c\)): The linear trend model typically reports a slightly lower \(\text{AIC}_c\) than the damped model on this series, meaning the penalty parameter for damping does not yield a substantial in-sample likelihood gain.
Practical Trajectory: Gas production shows steady upward momentum, but over longer horizons (\(h > 3\text{--}5\text{ years}\)), an unconstrained linear trend continues upward indefinitely at an aggressive rate.
Forecast Evaluation: Cross-validation accuracy often shows comparable short-term errors between the two models, but damping provides a more conservative, realistic forecast by preventing excessive linear over-projection into the future.
Recall your retail time series data (from Exercise 7 in Section 2.10).
Why is multiplicative seasonality necessary for this series?
Apply Holt-Winters’ multiplicative method to the data. Experiment with making the trend damped.
Compare the RMSE of the one-step forecasts from the two methods. Which do you prefer?
Check that the residuals from the best method look like white noise.
Now find the test set RMSE, while training the model to the end of 2010. Can you beat the seasonal naïve approach from Exercise 7 in Section 5.11?
When plotting retail turnover over time, the series exhibits an upward trend along with distinct seasonal fluctuations (typically peaking in December due to holiday spending).
As the overall level (mean turnover) of the series increases, the magnitude and amplitude of the seasonal swings increase proportionally.
Additive seasonality assumes that the seasonal variation remains constant in absolute terms regardless of the level. Multiplicative seasonality is necessary because seasonal effects behave as relative percentage changes proportional to the underlying trend/level.
## # A tibble: 2 × 11
## State Industry .model sigma2 log_lik AIC AICc BIC MSE AMSE MAE
## <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Western … Hardwar… HW Mu… 0.00602 -2069. 4172. 4174. 4242. 30.4 42.7 0.0529
## 2 Western … Hardwar… HW Da… 0.00635 -2077. 4189. 4191. 4263. 30.7 43.3 0.0538
Standard Holt-Winters’ multiplicative method corresponds to an \(\text{ETS}(M, A, M)\) model: multiplicative errors, additive linear trend, and multiplicative seasonality.
The damped version corresponds to \(\text{ETS}(M, Ad, M)\), where a damping parameter \(\phi\) (\(0 < \phi < 1\)) attenuates the slope of the trend over time, preventing long-range linear over-projection.
## # A tibble: 2 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 HW Multiplicative 5.51 3.83 5.44 0.384
## 2 HW Damped 5.54 3.85 5.41 0.386
## # A tibble: 2 × 4
## .model AIC AICc BIC
## <chr> <dbl> <dbl> <dbl>
## 1 HW Multiplicative 4172. 4174. 4242.
## 2 HW Damped 4189. 4191. 4263.
The one-step training RMSE is obtained via
accuracy(fit). In-sample, the unconstrained linear model
often achieves a slightly lower or comparable RMSE because it fits
trends without shrinkage.
To decide preference:
Check \(\text{AIC}_c\) via
glance(fit): \(\text{AIC}_c\) balances fit quality with a
penalty for the extra damping parameter \(\phi\).
If \(\text{AIC}_c\) favors the damped model, or if long-range horizons require avoiding runaway growth, the damped model is preferred. If \(\text{AIC}_c\) and RMSE both favor the standard model and the trend shows sustained momentum, standard Holt-Winters is preferred.
## # A tibble: 2 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 hw_mult 5.51 3.83 5.44 0.384
## 2 hw_damped 5.54 3.85 5.41 0.386
## # A tibble: 1 × 5
## State Industry .model lb_stat lb_pvalue
## <chr> <chr> <chr> <dbl> <dbl>
## 1 Western Australia Hardware, building and garden supp… hw_mu… 27.0 0.000339
## # A tibble: 3 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 hw_damped 60.8 55.8 32.4 6.36
## 2 hw_mult 41.8 37.7 21.9 4.30
## 3 snaive 64.2 59.2 34.7 6.76
gg_tsresiduals() verifies:
Innovation residuals plot: Centered at 0 with constant variance over time.
ACF plot: Auto-correlations should stay within the blue 95% confidence bands.
Histogram: Residuals should approximate a bell-shaped, normal distribution.
The Ljung-Box test tests the null hypothesis that residuals are independently distributed (white noise). A \(p\text{-value} > 0.05\) indicates the residuals do not significantly differ from white noise.
## # A tibble: 3 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 HW Damped 60.8 55.8 32.4 6.36
## 2 HW Multiplicative 41.8 37.7 21.9 4.30
## 3 Seasonal Naïve 64.2 59.2 34.7 6.76
The Seasonal Naïve benchmark simply replicates the corresponding month from the previous year (\(y_t = y_{t-m}\)), ignoring longer-term multi-year trend changes.
Both Holt-Winters multiplicative methods capture both the level shift, trend rate, and multiplicative seasonal adjustments. As a result, the test set RMSE for the Holt-Winters models is substantially lower than that of the Seasonal Naïve benchmark.
For the same retail data, try an STL decomposition applied to the Box-Cox transformed series, followed by ETS on the seasonally adjusted data. How does that compare with your best previous forecasts on the test set?
## # A tibble: 4 × 5
## .model RMSE MAE MAPE MASE
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 hw_damped 60.8 55.8 32.4 6.36
## 2 hw_mult 41.8 37.7 21.9 4.30
## 3 snaive 64.2 59.2 34.7 6.76
## 4 stl_ets 37.7 33.3 19.4 3.79
How decomposition_model() operates with STL and
Box-Cox:
Box-Cox transformation: First stabilizes the expanding variance across the time series.
STL decomposition: Breaks the transformed series into trend-cycle, seasonal, and remainder components using loess smoothing. By definition, STL handles additive seasonality, which is valid here because the Box-Cox transformation has stabilized the variance.
ETS modeling: The seasonally adjusted component
(season_adjust = trend + remainder) is non-seasonal, so it
is modeled using a non-seasonal ETS specification
(season("N")).
Seasonal component: By default,
decomposition_model() forecasts the seasonal component
using a seasonal naïve (SNAIVE) method.
Recomposition & Back-transformation: The forecasts of the seasonal component and the seasonally adjusted component are added together, and fable automatically applies the inverse Box-Cox transformation to return forecasts on the original dollar scale.
Comparison with previous test set forecasts:
Versus Seasonal Naïve: Both Holt-Winters and the
STL + ETS model substantially outperform SNAIVE because
they capture the macroeconomic upward drift rather than just repeating
previous year levels.
Versus Holt-Winters Multiplicative:
In many retail series, the STL + ETS combination yields a lower or highly competitive test set RMSE compared to standard Holt-Winters.
Because retail series often experience structural shifts in consumer spending and evolving holiday patterns, allowing the trend-cycle and seasonal patterns to separate via loess smoothing prevents the trend component from distorting the seasonal indices during sudden swings or economic fluctuations (such as the 2008 GFC).