library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(TSA)
## Warning: package 'TSA' was built under R version 4.4.3
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
library(forecast)
## Registered S3 methods overwritten by 'forecast':
## method from
## fitted.Arima TSA
## plot.Arima TSA
Coba bangkitkan data tie series model ARIMA(1, 1, 1). Tentukan nilai AR dan MA secara acak.
# Set seed untuk reprodusibilitas
set.seed(123)
# Pnjang Data
n <- 200
# Parameter ARIMA(p=1, d=1, q=1)
ar <- 0.7 # AR(1)
ma <- -0.5 # MA(1)
# Simulasi data
ts_arima <- arima.sim(model = list(order = c(1, 1, 1), ar = ar, ma = ma), n = n)
# Plot
ts.plot(ts_arima, main = "Simulasi Data ARIMA(1,1,1)")
acf(ts_arima)
pacf(ts_arima)
adf.test(ts_arima)
##
## Augmented Dickey-Fuller Test
##
## data: ts_arima
## Dickey-Fuller = -2.449, Lag order = 5, p-value = 0.388
## alternative hypothesis: stationary
Dikarenakan p-value = 0.388 > 0.05 sehingga disimpulkan data tidaj stasioner dan harus dilakukan proses differencing.
diff1 <- diff(ts_arima)
acf(diff1)
pacf(diff1)
adf.test(diff1)
## Warning in adf.test(diff1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff1
## Dickey-Fuller = -5.4572, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
karena nilai p-value = 0.01 < 0.05 sehingga disimpulkan data sudah stasioner
data.ts <- ts(diff1)
head(data.ts)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] -0.4362295 -1.1367886 -0.4798151 -1.2528876 -1.0929103 -1.0256309
acf(data.ts)
pacf(data.ts)
eacf(data.ts)
## AR/MA
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x 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 x o o o o o o o o o o o o
## 4 x x 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 x o o o o o o o o o o
## 7 o x x x x o o o o o o o o o
auto.arima(data.ts)
## Series: data.ts
## ARIMA(2,0,2) with zero mean
##
## Coefficients:
## ar1 ar2 ma1 ma2
## -0.1116 0.6336 0.3108 -0.6250
## s.e. 0.2175 0.1701 0.2294 0.2122
##
## sigma^2 = 0.8631: log likelihood = -267.28
## AIC=544.57 AICc=544.88 BIC=561.06
Kandidat Model ARIMA(1,1,1)ARIMA(1,1,3) ARIMA(0,1,1) ARIMA(2,0,2)
auto.arima(ts_arima)
## Series: ts_arima
## ARIMA(2,1,2)
##
## Coefficients:
## ar1 ar2 ma1 ma2
## -0.1116 0.6336 0.3108 -0.6250
## s.e. 0.2175 0.1701 0.2294 0.2122
##
## sigma^2 = 0.8631: log likelihood = -267.28
## AIC=544.57 AICc=544.88 BIC=561.06
arima(data.ts, order = c(1,1,1), method = "ML")
##
## Call:
## arima(x = data.ts, order = c(1, 1, 1), method = "ML")
##
## Coefficients:
## ar1 ma1
## 0.1488 -1.0000
## s.e. 0.0706 0.0164
##
## sigma^2 estimated as 0.8926: log likelihood = -273.56, aic = 551.13
arima(data.ts, order = c(2,0,2), method = "ML")
##
## Call:
## arima(x = data.ts, order = c(2, 0, 2), method = "ML")
##
## Coefficients:
## ar1 ar2 ma1 ma2 intercept
## -0.1096 0.6350 0.3087 -0.6269 -0.0214
## s.e. 0.2164 0.1692 0.2283 0.2112 0.0931
##
## sigma^2 estimated as 0.8456: log likelihood = -267.26, aic = 544.51
Berdasarkan hasil Pemodelan, diperoleh model dengan nilai AIC terkecil adalah ARIMA(2,0,2), hal ini dikarenakan data yang terbaca adalah data hasil differencing. Diperoleh pembelajaran bahwa, data time series yang dibangkitkan dengan model tertentu, belum tentu akan sama dengan hasil pemodelan terbaiknya.Hal ini diduga karena adanya faktor-faktor lain yang mempengaruhi proses pemodelan.