Library

library("readxl")
library("tseries") 
library("forecast") 
library("TTR") 
library("TSA") 
library("graphics")
library("dplyr")
library("tidyverse")
library ("zoo")
library ("lmtest")
library ("lubridate")

DATA

# Membaca file Excel
data <- read_excel("Inflasi_UAS.xlsx")
data.ts <- ts(data$`Data Inflasi`, start = c(2010,1), frequency = 12)
data.ts
##       Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
## 2010 3.72 3.81 3.43 3.91 4.16 5.05 6.22 6.44 5.80 5.67 6.33 6.96
## 2011 7.02 6.84 6.65 6.16 5.98 5.54 4.61 4.79 4.61 4.42 4.15 3.79
## 2012 3.65 3.56 3.97 4.50 4.45 4.53 4.56 4.58 4.31 4.61 4.32 4.30
## 2013 4.57 5.31 5.90 5.57 5.47 5.90 8.61 8.79 8.40 8.32 8.37 8.38
## 2014 8.22 7.75 7.32 7.25 7.32 6.70 4.53 3.99 4.53 4.83 6.23 8.36
plot(data.ts, xlab = "Tahun", ylab = "Inflasi", main = "Plot Time Series")

seasonplot (data.ts,12,main="Season Plot of Inflasi",xlab="Bulan",ylab="Data Inflasi",year.labels = TRUE, col=rainbow(18))

# Cek Stasioner Varian

lambda <- BoxCox.lambda(data.ts)
lambda
## [1] -0.9999242

Transformasi Boxcox

trans1 <- BoxCox(data.ts, lambda)
BoxCox.lambda(1,1/(data.ts))
## [1] 1
plot (trans1,xlab="Bulan",ylab="Data Inflasi",main="plot Time Series Setelah Transformasi", col = "green")
grid()

# Cek stasioner Mean

adf.test (trans1)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  trans1
## Dickey-Fuller = -2.3489, Lag order = 3, p-value = 0.4337
## alternative hypothesis: stationary

Differencing

diff1 <- diff(trans1)
adf.test(diff1)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff1
## Dickey-Fuller = -3.2215, Lag order = 3, p-value = 0.0927
## alternative hypothesis: stationary
diff2 <- diff(diff1)
adf.test(diff2)
## Warning in adf.test(diff2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff2
## Dickey-Fuller = -6.1694, Lag order = 3, p-value = 0.01
## alternative hypothesis: stationary
plot (diff2,xlab="Bulan",ylab="Data Inflasi",main="plot Time Series Setelah Differencing", col = "green")

# Identifikasi Model ## AR/MA

acf(diff2, lag.max=48)

pacf (diff2, lag.max=48)

eacf (diff2)
## AR/MA
##   0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 o o o o o o o o o o o  o  o  o 
## 1 x o o o o o o o o o o  o  o  o 
## 2 x x o o o o o o o o o  o  o  o 
## 3 x o o o o o o o o o o  o  o  o 
## 4 x o o o o o o o o o o  o  o  o 
## 5 x o o o o o o o o o o  o  o  o 
## 6 x o o o o o o o o o o  o  o  o 
## 7 o x x o o o o o o o o  o  o  o

020;021;121;222;122

Seasonal

diff_s=diff(data.ts,lag=12)
acf(diff_s, lag.max=48)

pacf (diff_s, lag.max=48)

auto.arima(data.ts)
## Series: data.ts 
## ARIMA(0,1,1)(0,0,1)[12] 
## 
## Coefficients:
##          ma1     sma1
##       0.4931  -0.6608
## s.e.  0.1119   0.1862
## 
## sigma^2 = 0.2715:  log likelihood = -47.78
## AIC=101.55   AICc=101.99   BIC=107.79

Membuat Model

model1 = Arima(data.ts, order = c(0,2,0))
model2 = Arima(data.ts, order = c(0,2,1))
model3 = Arima(data.ts, order = c(1,2,1))
model4 = Arima(data.ts, order = c(2,2,2))

model5 = Arima(data.ts, order = c(0,2,0), seasonal = list(order=c(1,0,0), period=12))
model6 = Arima(data.ts, order = c(0,2,1), seasonal = list(order=c(1,0,0), period=12))
model7 = Arima(data.ts, order = c(1,2,1), seasonal = list(order=c(1,0,0), period=12))
model8 = Arima(data.ts, order = c(2,2,2), seasonal = list(order=c(1,0,0), period=12))
model9 = Arima(data.ts, order = c(0,1,1), seasonal = list(order=c(0,0,1), period=12))

Memilih Model

models <- list(model1, model2, model3, model4, model5, model6, model7, model8, model9)

results <- data.frame(
  Model = paste0("Model", 1:9),
  AIC = NA,
  MSE = NA,
  RMSE = NA,
  MAE = NA,
  MAPE = NA
)

for (i in 1:9) {
  results$AIC[i] <- AIC(models[[i]])
  acc <- accuracy(models[[i]])
  results$MSE[i] <- (acc[1, "RMSE"])^2
  results$RMSE[i] <- acc[1, "RMSE"]
  results$MAE[i] <- acc[1, "MAE"]
  results$MAPE[i] <- acc[1, "MAPE"]
  
}
print(results)
##    Model      AIC       MSE      RMSE       MAE     MAPE
## 1 Model1 128.5675 0.5017871 0.7083693 0.4887742 8.849529
## 2 Model2 127.0369 0.4702869 0.6857747 0.4793933 8.495494
## 3 Model3 119.8064 0.3817525 0.6178612 0.4192617 7.435900
## 4 Model4 120.9178 0.3517309 0.5930691 0.4256700 7.640758
## 5 Model5 119.6819 0.3954258 0.6288289 0.4301155 7.607867
## 6 Model6 116.6805 0.3552801 0.5960538 0.4129733 7.130543
## 7 Model7 111.8386 0.3015076 0.5490970 0.3716799 6.440342
## 8 Model8 113.9035 0.2906088 0.5390814 0.3613097 6.330042
## 9 Model9 101.5528 0.2579475 0.5078853 0.3282644 5.798182
coeftest(model7)
## 
## z test of coefficients:
## 
##      Estimate Std. Error z value  Pr(>|z|)    
## ar1   0.45205    0.13750  3.2876 0.0010104 ** 
## ma1  -1.00000    0.13947 -7.1698 7.512e-13 ***
## sar1 -0.47344    0.13281 -3.5647 0.0003642 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
checkresiduals(model7)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,2,1)(1,0,0)[12]
## Q* = 6.3277, df = 9, p-value = 0.7067
## 
## Model df: 3.   Total lags used: 12

PREDIKSI

pred.AMD <- forecast(model7, h=12)
pred.AMD
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 2015       9.473729 8.731833 10.21562 8.339097 10.60836
## Feb 2015      10.238432 8.919128 11.55774 8.220731 12.25613
## Mar 2015      10.760071 8.934255 12.58589 7.967726 13.55242
## Apr 2015      11.009954 8.737613 13.28229 7.534709 14.48520
## May 2015      11.147753 8.475261 13.82025 7.060529 15.23498
## Jun 2015      11.591525 8.553979 14.62907 6.946000 16.23705
## Jul 2015      12.759777 9.383883 16.13567 7.596793 17.92276
## Aug 2015      13.152082 9.458480 16.84568 7.503206 18.80096
## Sep 2015      13.031155 9.036103 17.02621 6.921251 19.14106
## Oct 2015      13.022990 8.739548 17.30643 6.472032 19.57395
## Nov 2015      12.493645 7.932497 17.05479 5.517972 19.46932
## Dec 2015      11.618508 6.788539 16.44848 4.231708 19.00531
plot(pred.AMD, xlab="Tahun", ylab="Harga ($)", main="Plot Time Series Setelah Differencing", col = "blue")
grid()