library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(TSA)
##
## 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 time series dengan model ARIMA(1,1,1). Tentukan nilai AR dan MA
set.seed(123)
n = 200
ar = 0.7
ma = -0.5
ts_arima = arima.sim(model=list(order=c(1,1,1), ar=ar, ma=ma), n=n)
ts.plot(ts_arima, main = "Simulasi Data ARIMA(1,1,1)")
## Melakukan Pemodelan ## 1. Buat Plot ACF dan PACF 2. Cek
kestasioneritas dengan ADF test 3. Melakukan differencing 4. Buat Plot
ACF dan PACF 5. Cek kestasioneritas dengan ADF test 6. Ubah ke data ts
7. Buat Kandidat Model melalui ACF, PACF, dan EACF 8. Bandingkan dengan
hasil auto.arima 9. Cek AIC terkecil
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
Karena nilai p-value = 0,388 > 0,05 sehingga perlu dilakukan 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 sehigga 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(1,1,3), method="ML")
##
## Call:
## arima(x = data.ts, order = c(1, 1, 3), method = "ML")
##
## Coefficients:
## ar1 ma1 ma2 ma3
## -0.8559 0.0335 -0.9642 -0.0693
## s.e. 0.0800 0.1018 0.0443 0.0772
##
## sigma^2 estimated as 0.8611: log likelihood = -270.25, aic = 548.49
arima(data.ts, order=c(0,1,1), method="ML")
##
## Call:
## arima(x = data.ts, order = c(0, 1, 1), method = "ML")
##
## Coefficients:
## ma1
## -0.9294
## s.e. 0.1078
##
## sigma^2 estimated as 0.93: log likelihood = -276.14, aic = 554.28
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 adlah ARIMA(2,0,2), hal ini dikarenakan data yang terbaca adalah data differencing