In the past two years, Indonesia experienced economic slowdown because of the pandemic. Nevertheless, the pandemic is become endemic and about 73% citizen has been vaccinated twice. Indonesia is in economic recovery. Then, how is the prosect of Indonesia economy for the next 5 quarters? To answer that question, we will forecast Indonesia GDP using ARIMA model.
Before started, we need to install some libraries.
library(readxl)
library(aTSA)
library(forecast)
library(lmtest)
Then, we import the data. Data consist of Indonesia GDP quarterly ranging from 2010Q1 to 2022Q3. After that, it has to cast into time series format in order to be able performing the analysis in ARIMA.
gdp <- read_excel("D:/KARIR/R Portofolio/arima/univariate/gdpq.xlsx")
gdp <- gdp[,c(-1)]
gdp <- ts(gdp, start= c(2010, 1), frequency = 4)
As we can see, Indonesia economy had plummeted in 2020. Then, began
to recover starting in the end of 2021.
In the model selection, we need to find the apprpriate order of
Autroregressive and Moving Avarage. Through Autocorrelation Function
(ACF), and Partial Autocorrelation Function (PACF) plots, we can
determine the AR and MA orders.
As we can see, ACF is decreasing gradually but PACF drops sharply. Thus, the appropriate model is AR(1). Nonetheles, there is a function called auto.arima() in forecast package that can perform the best selection model in ARIMA.
auto.arima(gdp, trace = T)
##
## ARIMA(2,0,2)(1,1,1)[4] with drift : Inf
## ARIMA(0,0,0)(0,1,0)[4] with drift : 1171.054
## ARIMA(1,0,0)(1,1,0)[4] with drift : 1140.655
## ARIMA(0,0,1)(0,1,1)[4] with drift : Inf
## ARIMA(0,0,0)(0,1,0)[4] : 1231.949
## ARIMA(1,0,0)(0,1,0)[4] with drift : 1146.211
## ARIMA(1,0,0)(2,1,0)[4] with drift : 1134.265
## ARIMA(1,0,0)(2,1,1)[4] with drift : Inf
## ARIMA(1,0,0)(1,1,1)[4] with drift : Inf
## ARIMA(0,0,0)(2,1,0)[4] with drift : 1168.568
## ARIMA(2,0,0)(2,1,0)[4] with drift : 1136.836
## ARIMA(1,0,1)(2,1,0)[4] with drift : 1136.844
## ARIMA(0,0,1)(2,1,0)[4] with drift : 1147.267
## ARIMA(2,0,1)(2,1,0)[4] with drift : Inf
## ARIMA(1,0,0)(2,1,0)[4] : 1138.73
##
## Best model: ARIMA(1,0,0)(2,1,0)[4] with drift
## Series: gdp
## ARIMA(1,0,0)(2,1,0)[4] with drift
##
## Coefficients:
## ar1 sar1 sar2 drift
## 0.7846 -0.6568 -0.5197 24340.830
## s.e. 0.0967 0.1455 0.1564 2772.202
##
## sigma^2 = 1.402e+09: log likelihood = -561.4
## AIC=1132.8 AICc=1134.26 BIC=1142.05
So, the best model is ARIMA(1,0,0) with seasonal (2,1,0) in 4 period and include a drift (constant).
After we have the best model, we will run it to get the estimation.
model <- Arima(gdp, order = c(1,0,0),
seasonal = list(order=c(2,1,0), period = 3),
include.drift = T)
coeftest(model)
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## ar1 0.54167 0.13389 4.0458 5.215e-05 ***
## sar1 -0.29326 0.11302 -2.5947 0.009469 **
## sar2 -0.65533 0.10336 -6.3404 2.292e-10 ***
## drift 25066.46407 2846.94550 8.8047 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Forecast the value of Indonesia gdp for 5 periods ahead. The grey color area around the projection line tells us that the longer the period of forecasting from present time the confidence interval more wider.
forecasting <- forecast(model, h = 5)
forecasting
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2022 Q4 2968379 2899917 3036842 2863675 3073084
## 2023 Q1 2996260 2918399 3074122 2877182 3115339
## 2023 Q2 2993908 2913498 3074319 2870931 3116886
## 2023 Q3 3048998 2949106 3148890 2896227 3201770
## 2023 Q4 3055120 2950196 3160043 2894652 3215587