library(tseries)
## Warning: package 'tseries' was built under R version 4.4.3
## 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)
## Warning: package 'forecast' was built under R version 4.4.3
## Registered S3 methods overwritten by 'forecast':
## method from
## fitted.Arima TSA
## plot.Arima TSA
coba simulasikan 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 ARIAMA(1,1,1)")
### Melakukan Pemodelan 1. Buat plot ACF dan PACF
Cek kestasioneritas dengan dengan ADF Test
Melakukan differencing
Buat Plot ACF daan PACF
Cek kestasioneritas dengan ADF Test
Ubah ke data ts
Buat Kandidat Model melalui ACF, PACF, dan EACF
Bandingkan dengan hasil auto.arima
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
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
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
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(0,1,2), method="ML")
##
## Call:
## arima(x = data.ts, order = c(0, 1, 2), method = "ML")
##
## Coefficients:
## ma1 ma2
## -0.8590 -0.1410
## s.e. 0.0722 0.0703
##
## sigma^2 estimated as 0.8938: log likelihood = -273.72, aic = 551.44
arima(data.ts, order=c(1,1,2), method="ML")
##
## Call:
## arima(x = data.ts, order = c(1, 1, 2), method = "ML")
##
## Coefficients:
## ar1 ma1 ma2
## -0.8162 -0.0500 -0.9500
## s.e. 0.0731 0.0457 0.0454
##
## sigma^2 estimated as 0.8643: log likelihood = -270.66, aic = 547.31
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)