Pembangkitan Data Time Series

coba bangkitkan data timeseries dengan model ARIMA(1,1,1). Tentukan nilai AR

# Set seed untuk reprodusibilitas
set.seed(123)

# Panjang Data
n <- 200

Parameter ARIMA(p=1, del=1, q=1)

ar <- 0.7 #AR(1)
ma <- -0.5 #AR(2)

Simulasi Data

ts_arima <- arima.sim(model= list(order= c(1,1,1), ar = ar, ma = ma), n = n)

Membuat Plot

ts.plot(ts_arima, main = "Simulasi Data Arima(1,1,1,)")

library(tseries)
## Warning: package 'tseries' was built under R version 4.3.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

Menentukan Pemodelan

  1. Buat Plot ACF
acf(ts_arima)

pacf(ts_arima)

  1. Cek kestasioneran dengan ADF test
library(tseries)
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
  1. Melakukan Diferencing
diff1 <- diff(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
  1. Buat Plot ACF dan PACF
acf(diff1)

pacf(diff1)

  1. Cek kestasioneran dengan ADF test
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
  1. Ubah ke data ts
data.ts<- ts(diff1)
head(data.ts)
## [1] -0.4362295 -1.1367886 -0.4798151 -1.2528876 -1.0929103 -1.0256309
  1. Buat Kandidat model melalui ACF dan PACF
library(TSA)
## Warning: package 'TSA' was built under R version 4.3.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.3.3
## Registered S3 methods overwritten by 'forecast':
##   method       from
##   fitted.Arima TSA 
##   plot.Arima   TSA
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
  1. Bandingkan dengan hasil auto.arima Kandidat Model ARIMA (1,1,1) ARIMA (1,1,3) ARIMA (0,1,1) ARIMA (2,0,2)

  2. Cek AIC Terkecil

  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