── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ tsibble::interval() masks lubridate::interval()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following object is masked from 'package:tsibble':
index
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
######################### Warning from 'xts' package ##########################
# #
# The dplyr lag() function breaks how base R's lag() function is supposed to #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
# source() into this session won't work correctly. #
# #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
# dplyr from breaking base R's lag() function. #
# #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
# #
###############################################################################
Attaching package: 'xts'
The following objects are masked from 'package:dplyr':
first, last
Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
# A tibble: 10 × 6
.model term estimate std.error statistic p.value
<chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 ETS alpha 1.000 NA NA NA
2 ETS beta 0.112 NA NA NA
3 ETS phi 0.980 NA NA NA
4 ETS l[0] 127. NA NA NA
5 ETS b[0] 0.660 NA NA NA
6 ARIMA ma1 0.547 0.0554 9.87 2.95e-20
7 ARIMA ma2 0.0627 0.0625 1.00 3.16e- 1
8 ARIMA ma3 -0.116 0.0564 -2.07 3.97e- 2
9 ARIMA sma1 -0.194 0.0543 -3.58 3.97e- 4
10 ARIMA constant 0.355 0.0305 11.6 2.15e-26
fc <- fit |>forecast(h =nrow(test))fc |>accuracy(both) |>select(.model, RMSE, MAE, MAPE, MASE)
# A tibble: 2 × 5
.model RMSE MAE MAPE MASE
<chr> <dbl> <dbl> <dbl> <dbl>
1 ARIMA 17.0 11.0 3.74 2.52
2 ETS 23.0 15.3 5.27 3.53
fc |>autoplot(both, level =95) +facet_wrap(~ .model, ncol =1) +labs(title ="ETS vs ARIMA — 80/20 Test Split",subtitle ="Vertical line = train/test cutoff",x =NULL, y ="CPI Index") +geom_vline(xintercept =as.numeric(yearmonth("2017 Feb")),linetype ="dashed", colour ="black")
No, although both models do no not forecast the positive shock, ARIMA performs better across all accuracy metrics and has a tighter confidence interval.
fc_all |>autoplot(both, level =95) +facet_wrap(~ .model, ncol =1) +geom_vline(xintercept =as.numeric(yearmonth("2017 Feb")),linetype ="dashed", colour ="black") +labs(title ="ETS vs ARIMA vs Dynamic Regression — 80/20 Test Split",subtitle ="Dashed line = train/test cutoff",x =NULL, y ="CPI Index")
Out of the 3 models (ETS, ARIMA, ARIMA with Oil regressor), the dynamic regression (CPI~Oil) ARIMA(0,1,1)(0,1,1)[12] wins out on every metric, and also has a tighter confidence interval than the basic ARIMA model. So, oil price, which can push inflation as oil is a raw input in many goods, is a decent regressor.