2025-09-30
Let’s start by loading the necessary packages for our analysis:
# Load built-in dataset
data(global_economy)
# Filter for Australia
aus_economy <- global_economy |> filter(Country == "Australia")
# View the data structure
(aus_economy) |> slice_sample(n = 8)# A tsibble: 8 x 9 [1Y]
# Key: Country [1]
Country Code Year GDP Growth CPI Imports Exports Population
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Australia AUS 1986 1.82e11 4.06 44.5 18.1 15.0 16018400
2 Australia AUS 1964 2.38e10 6.98 8.40 13.8 14.9 11167000
3 Australia AUS 1981 1.77e11 3.34 30.0 16.7 14.9 14927000
4 Australia AUS 1990 3.11e11 3.56 59.8 17.1 15.1 17065100
5 Australia AUS 1996 4.00e11 3.88 69.4 19.4 18.9 18311000
6 Australia AUS 1973 6.37e10 2.61 12.5 11.0 14.2 13380000
7 Australia AUS 2016 1.21e12 2.83 113. 21.5 19.3 24210809
8 Australia AUS 1994 3.22e11 3.98 64.6 18.5 18.0 17855000
Additive model: \(y_t = T_t + S_t + E_t\)
Multiplicative model: \(y_t = T_t \times S_t \times E_t\)
Where:
# Calculate features
aus_retail |>
features(Turnover, list(
trend_strength = feat_stl,
seasonal_strength = feat_stl
))# A tibble: 1 × 20
State Industry trend_strength_trend_strength trend_strength_seasona…¹
<chr> <chr> <dbl> <dbl>
1 Victoria Food retailing 0.999 0.959
# ℹ abbreviated name: ¹trend_strength_seasonal_strength_year
# ℹ 16 more variables: trend_strength_seasonal_peak_year <dbl>,
# trend_strength_seasonal_trough_year <dbl>, trend_strength_spikiness <dbl>,
# trend_strength_linearity <dbl>, trend_strength_curvature <dbl>,
# trend_strength_stl_e_acf1 <dbl>, trend_strength_stl_e_acf10 <dbl>,
# seasonal_strength_trend_strength <dbl>,
# seasonal_strength_seasonal_strength_year <dbl>, …
Formula: \(r_k = \frac{\sum_{t=k+1}^T (y_t - \bar{y})(y_{t-k} - \bar{y})}{\sum_{t=1}^T (y_t - \bar{y})^2}\)
\(\hat{y}_{T+h|T} = \bar{y}\)
\(\hat{y}_{T+h|T} = y_T\)
\(\hat{y}_{T+h|T} = y_{T+h-m(k+1)}\)
\(\hat{y}_{T+h|T} = y_T + \frac{h}{T-1}\sum_{t=2}^T (y_t - y_{t-1})\)
Forecast equation: \(\hat{y}_{t+1|t} = \alpha y_t + \alpha(1-\alpha) y_{t-1} + \alpha(1-\alpha)^2 y_{t-2} + \cdots\)
Smoothing equation: \(\ell_t = \alpha y_t + (1-\alpha)\ell_{t-1}\)
Where \(0 \leq \alpha \leq 1\) is the smoothing parameter.
Forecast equation: \(\hat{y}_{t+h|t} = \ell_t + h b_t\)
Level equation: \(\ell_t = \alpha y_t + (1-\alpha)(\ell_{t-1} + b_{t-1})\)
Trend equation: \(b_t = \beta(\ell_t - \ell_{t-1}) + (1-\beta)b_{t-1}\)
Additive seasonality: - \(\hat{y}_{t+h|t} = \ell_t + h b_t + s_{t+h-m(k+1)}\) - \(s_t = \gamma(y_t - \ell_{t-1} - b_{t-1}) + (1-\gamma)s_{t-m}\)
Series: Turnover
Model: ETS(M,A,M)
Smoothing parameters:
alpha = 0.2611645
beta = 0.005957878
gamma = 0.07008308
Initial states:
l[0] b[0] s[0] s[-1] s[-2] s[-3] s[-4] s[-5]
313.2514 3.284057 1.020786 0.9421796 0.9914176 1.175902 1.021539 1.015409
s[-6] s[-7] s[-8] s[-9] s[-10] s[-11]
0.9618333 0.9807726 0.9727921 0.9532951 0.9873115 0.9767631
sigma^2: 6e-04
AIC AICc BIC
5552.291 5553.738 5621.805
\((1-\phi_1B-\cdots-\phi_pB^p)(1-B)^d y_t = c + (1+\theta_1B+\cdots+\theta_qB^q)\varepsilon_t\)
ARIMA(p,d,q)(P,D,Q)\(_m\) includes: - Non-seasonal part: ARIMA(p,d,q) - Seasonal part: ARIMA(P,D,Q) with period m
# A tibble: 3 × 12
State Industry .model .type ME RMSE MAE MPE MAPE MASE RMSSE
<chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Victoria Food retaili… ETS Trai… 1.88 27.3 20.3 0.0787 1.81 0.301 0.337
2 Victoria Food retaili… ARIMA Trai… 1.87 28.8 21.2 0.0753 1.84 0.315 0.355
3 Victoria Food retaili… SNAIVE Trai… 65.4 81.1 67.3 5.60 5.74 1 1
# ℹ 1 more variable: ACF1 <dbl>
# A tibble: 3 × 12
.model State Industry .type ME RMSE MAE MPE MAPE MASE RMSSE ACF1
<chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 ARIMA Victoria Food re… Test NaN NaN NaN NaN NaN NaN NaN NA
2 ETS Victoria Food re… Test NaN NaN NaN NaN NaN NaN NaN NA
3 SNAIVE Victoria Food re… Test NaN NaN NaN NaN NaN NaN NaN NA
fpp3 package with tidyverse approachContact: Kamarul Imran Musa
Resources:
Time Series and Forecasting