library(fpp3)
<- aus_tobacco |>
tobacco summarise(Expenditure = sum(Expenditure))
|> autoplot(Expenditure) tobacco
Activities: Week 10
Australian tobacco expenditure
In this exercise, we will compare an ETS model, an ARIMA model and an STL+ARIMA model fitted to Australian tobacco expenditure data.
First we will find an appropriate STL decomposition for this data set.
|> tobacco model( stl = STL(log(Expenditure) ~ season(window = ???) + trend(window = ???)) |> ) components() |> autoplot()
Now fit an ETS, ARIMA and STL+ARIMA model with the same window values. For the ARIMA and STL+ARIMA models, use a log transformation.
<- tobacco |> fit model( ets = ETS(Expenditure), arima = ARIMA(log(Expenditure)), stl_arima = decomposition_model( STL(log(Expenditure) ~ season(window = ???) + trend(window = ???)), ARIMA(season_adjust), SNAIVE(season_year) ) )
Write down the equations for each model.
|> select(ets) |> report() fit |> select(arima) |> report() fit |> select(stl_arima) |> report() fit
Check if the residuals from each model look like white noise
|> select(ets) |> gg_tsresiduals() fit |> select(arima) |> gg_tsresiduals() fit |> select(stl_arima) |> gg_tsresiduals() fit
Which model fits the data best?
|> accuracy() fit
Do the forecasts look similar?
|> fit forecast(h = 24) |> autoplot(tobacco |> filter(year(Quarter) >= 2010), level = 80, alpha = 0.5)
Find the one-step median forecast and compute the 95% prediction interval from first principles. Check that you get the same result as obtained with the following code.
|> fit select(arima) |> forecast(h = 1) |> mutate( .median = median(Expenditure), PI = hilo(Expenditure, level = 95) )|> select(arima) |> report() fit