misal: AR = 0.5 MA = -0.3 n = 200
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.5.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
set.seed(456)
n <- 200
ar <- 0.5
ma <- -0.3
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)",
ylab="Nilai",
xlab="Waktu")
acf(ts_arima,
main="ACF Data Awal")
pacf(ts_arima,
main="PACF Data Awal")
adf.test(ts_arima)
##
## Augmented Dickey-Fuller Test
##
## data: ts_arima
## Dickey-Fuller = -2.4717, Lag order = 5, p-value = 0.3785
## alternative hypothesis: stationary
diff1 <- diff(ts_arima)
ts.plot(diff1,
main="Data Setelah Differencing")
acf(diff1,
main="ACF Setelah Differencing")
pacf(diff1,
main="PACF Setelah Differencing")
adf.test(diff1)
## Warning in adf.test(diff1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff1
## Dickey-Fuller = -5.9035, 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] 1.2453574 1.2180758 1.9663487 -0.9538095 1.9026933 2.1040759
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 x o o o o o o o o o o o o
## 1 x o o x o o o o o o o o o o
## 2 o x o o o o o o o o o o o o
## 3 o x x o o o o o o o o o o o
## 4 o x x x o o o o o o o o o o
## 5 x x o x o o o o o o o o o o
## 6 x x o x o o o o o o o o o o
## 7 x x x x o x o o o o o o o o
auto.arima(data.ts)
## Series: data.ts
## ARIMA(3,0,2) with zero mean
##
## Coefficients:
## ar1 ar2 ar3 ma1 ma2
## -0.1986 -0.4312 0.2401 0.4254 0.6773
## s.e. 0.2430 0.3161 0.1009 0.2429 0.3005
##
## sigma^2 = 0.9581: log likelihood = -277.08
## AIC=566.16 AICc=566.59 BIC=585.95
auto.arima(ts_arima)
## Series: ts_arima
## ARIMA(3,1,2)
##
## Coefficients:
## ar1 ar2 ar3 ma1 ma2
## -0.1986 -0.4312 0.2401 0.4254 0.6773
## s.e. 0.2430 0.3161 0.1009 0.2429 0.3005
##
## sigma^2 = 0.9581: log likelihood = -277.08
## AIC=566.16 AICc=566.59 BIC=585.95
model1 <- arima(data.ts,
order=c(1,0,1),
method="ML")
model2 <- arima(data.ts,
order=c(1,0,2),
method="ML")
model3 <- arima(data.ts,
order=c(2,0,1),
method="ML")
model4 <- arima(data.ts,
order=c(2,0,2),
method="ML")
model1
##
## Call:
## arima(x = data.ts, order = c(1, 0, 1), method = "ML")
##
## Coefficients:
## ar1 ma1 intercept
## 0.5223 -0.2791 0.0213
## s.e. 0.1605 0.1738 0.1041
##
## sigma^2 estimated as 0.9565: log likelihood = -279.39, aic = 564.77
model2
##
## Call:
## arima(x = data.ts, order = c(1, 0, 2), method = "ML")
##
## Coefficients:
## ar1 ma1 ma2 intercept
## 0.2981 -0.0836 0.1613 0.0215
## s.e. 0.2085 0.2020 0.0908 0.1053
##
## sigma^2 estimated as 0.9451: log likelihood = -278.21, aic = 564.41
model3
##
## Call:
## arima(x = data.ts, order = c(2, 0, 1), method = "ML")
##
## Coefficients:
## ar1 ar2 ma1 intercept
## 0.1982 0.1327 0.0261 0.0216
## s.e. 0.3100 0.1034 0.3068 0.1054
##
## sigma^2 estimated as 0.9512: log likelihood = -278.83, aic = 565.66
model4
##
## Call:
## arima(x = data.ts, order = c(2, 0, 2), method = "ML")
##
## Coefficients:
## ar1 ar2 ma1 ma2 intercept
## 1.1410 -0.7271 -0.9401 0.6950 0.0168
## s.e. 0.1805 0.1743 0.2014 0.1572 0.0874
##
## sigma^2 estimated as 0.9217: log likelihood = -275.79, aic = 561.59
AIC(model1,
model2,
model3,
model4)
## df AIC
## model1 4 566.7715
## model2 5 566.4116
## model3 5 567.6625
## model4 6 563.5852
Simulasi data time series dilakukan menggunakan model ARIMA(1,1,1) dengan parameter AR = 0.5 dan MA = -0.3. Hasil uji ADF menunjukkan bahwa data awal tidak stasioner sehingga dilakukan differencing satu kali. Setelah differencing, data menjadi stasioner dengan p-value sebesar 0.01. Berdasarkan perbandingan beberapa kandidat model menggunakan nilai AIC, diperoleh model terbaik yaitu ARIMA(2,0,2) dengan nilai AIC sebesar 563.5852. Model terbaik yang diperoleh berbeda dengan model pembangkitan awal ARIMA(1,1,1). Perbedaan ini menunjukkan bahwa proses identifikasi dan estimasi model ARIMA sangat dipengaruhi oleh variasi sampel, unsur acak dalam data simulasi, serta metode pemilihan model yang digunakan. Dengan demikian, model pembangkitan data tidak selalu sama dengan model terbaik hasil pemodelan.