Forecasting Annual Inflation Rates with ARIMA

library(forecast)
## Warning: package 'forecast' was built under R version 4.2.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(tseries)
## Warning: package 'tseries' was built under R version 4.2.3
library(readxl)

Input Data

Data consists of yearly inflation rate from 2001 to 2022. Historical data is sourced of Bank Indonesia official website (accessible at https://www.bi.go.id/id/statistik/indikator/target-inflasi.aspx).

inflation = read_excel("contextual_inflation.xlsx")
data = inflation$`Data Inflasi`
data
##  [1] 12.55 10.03  5.06  6.40 17.11  6.60  6.59 11.06  2.78  6.96  3.79  4.30
## [13]  8.38  8.36  3.35  3.02  3.61  3.13  2.72  1.68  1.87

Time Series Data

Time series data isĀ a collection of observations (behavior) for a single subject (entity) at different time intervalsĀ (generally equally spaced as in the case of metrics, or unequally spaced as in the case of events). Data used for ARIMA process has to be in the form of time series.

is.ts(data)
## [1] FALSE
data1 = ts(data)
data1
## Time Series:
## Start = 1 
## End = 21 
## Frequency = 1 
##  [1] 12.55 10.03  5.06  6.40 17.11  6.60  6.59 11.06  2.78  6.96  3.79  4.30
## [13]  8.38  8.36  3.35  3.02  3.61  3.13  2.72  1.68  1.87
is.ts(data1)
## [1] TRUE

Data Stationary

We check whether data is stationer or not.

adf.test(data1)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  data1
## Dickey-Fuller = -2.9388, Lag order = 2, p-value = 0.2148
## alternative hypothesis: stationary

Data Transformation

Since the original data is not stationary, transformation by applying the log function is done in order to make data more stationary.

dtrans = diff(log(data1),differences = 1)
plot(dtrans)

adf.test(dtrans)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dtrans
## Dickey-Fuller = -3.6484, Lag order = 2, p-value = 0.04654
## alternative hypothesis: stationary

ARIMA Modeling

Function auto.arima is used to find a model, suitable for data and projection.

arima1 = auto.arima(data1, trace = F, ic="aic")
arima1
## Series: data1 
## ARIMA(2,1,0) 
## 
## Coefficients:
##           ar1      ar2
##       -0.6698  -0.5578
## s.e.   0.1847   0.1784
## 
## sigma^2 = 12.74:  log likelihood = -53.25
## AIC=112.49   AICc=113.99   BIC=115.48

Data Projection

After model is formed, we perform projection of annual inflation rates for the next 7 years.

prediksi = forecast(arima1, h = 7)
prediksi
##    Point Forecast     Lo 80    Hi 80     Lo 95     Hi 95
## 22       2.322853 -2.251108 6.896813 -4.672416  9.318122
## 23       1.913559 -2.903334 6.730452 -5.453243  9.280361
## 24       1.935095 -2.986745 6.856935 -5.592210  9.462400
## 25       2.148974 -3.643558 7.941507 -6.709940 11.007889
## 26       1.993710 -4.122823 8.110242 -7.360720 11.348139
## 27       1.978401 -4.332601 8.289403 -7.673444 11.630246
## 28       2.075261 -4.689933 8.840455 -8.271211 12.421733