library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(forecast)
library(TTR)
library(TSA)
## Registered S3 methods overwritten by 'TSA':
## method from
## fitted.Arima forecast
## plot.Arima forecast
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
library(graphics)
set.seed(1001)
e<-rnorm(200,0,1)
n<-length(e)
Model \(Y_{t}\) diperoleh dari penguraian operator backshift sehingga perlu dilakukan penguraian operator backshift terlebih dahulu untuk ARIMA(0,2,2)
\(\psi_{p}(1-B)^{d}Y_{t}=\mu +\theta_{q}(B)e_{t}\)
\((1-B)^{2}Y_{t}=\mu +\theta_{2}(B)e_{t}\)
\((1-2B+B^{2})Y_{t}=\mu+(1-\theta_{1}(B)-\theta_{2}B^{2})e_{t}\)
\(Y_{t}-2Y_{t-1}+Y_{t-2}=\mu+e_{t}-\theta_{1}e_{t-1}-\theta_{2}e_{t-2}\)
\(Y_{t}=\mu+2Y_{t-1}-Y_{t-2}+e_{t}-\theta_{1}e_{t-1}-\theta_{2}e_{t-2}\)
Setelah model \(Y_{t}\) diperoleh bisa dilakukan proses selanjutnya yaitu membangun model dari data yang telah dibangkitkan dan dibuang 25 data pertama sehingga menjadi 175 data terakhir yang digunakan.
#Membangun model ARIMA (0,2,2) dengan mu=0.25, theta1=0.60, theta2=-0.75 dan membuang 25 data pertama
mu<-0.25
tetha1<-0.6
tetha2<--0.75
y<-c(1:n)
for (i in 3:n)
{y[i]<-mu+(2*y[i-1])-y[i-2]+e[i]-tetha1*e[i-1]-tetha2*e[i-2]}
y<-y[-c(1:25)]
Selanjutnya yaitu mengidentifikasi kestasioneran data dengan membuat time-series plot, correlogram, dan uji ADF
plot.ts(y,lty=1,ylab=expression(Y[t]))
points(y)
acf(y,lag.max = 20)
adf.test(y, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
##
## Augmented Dickey-Fuller Test
##
## data: y
## Dickey-Fuller = -0.30197, Lag order = 5, p-value = 0.9897
## alternative hypothesis: stationary
Berdasarkan pola dari plot data \(Y_{t}\) tidak membentuk pola yang stasioner. Kemudian untuk correlogram menunjukkan pola yang menurun secara perlahan hal tersebut mengindikasikan bahwa data tersebut tidak stasioner dan untuk uji ADF, karena nilai \(p-value = 0.9897 >\alpha=0.05\) sehingga terima \(H_{0}\) yang artinya data tidak stasioner. Berdasarkan ketiga cara untuk menentukan kestasioneran, ketiganya memberikan kesimpulan bahwa data yang digunakan merupakan data yang tidak stasioner sehingga diperlukan proses pembedaan hingga data menjadi stasioner.
y.dif1<-diff(y,differences = 1)
plot.ts(y.dif1,lty=1)
points(y.dif1)
acf(y.dif1,lag.max = 20)
adf.test(y.dif1, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
##
## Augmented Dickey-Fuller Test
##
## data: y.dif1
## Dickey-Fuller = -3.3436, Lag order = 5, p-value = 0.06611
## alternative hypothesis: stationary
Berdasarkan hasil differencing ordo 1 diperoleh kesimpulan bahwa data belum stasioner dikarenakan nilai \(p-value = 0.066 >\alpha=0.05\) sehingga perlu dilakukan differencing ordo 2.
#Differencing ordo 2
#Cara 1
y.dif2_1<-diff(y,differences = 2)
acf(y.dif2_1,lag.max = 20)
head(y.dif2_1)
## [1] 1.1378045 -1.8735359 -0.8009995 1.2195886 -0.9668539 0.3335778
plot.ts(y.dif2_1,lty=1)
points(y.dif2_1)
#Cara 2
y.dif2_2<-diff(y.dif1,differences = 1)
acf(y.dif2_2,lag.max = 20)
head(y.dif2_2)
## [1] 1.1378045 -1.8735359 -0.8009995 1.2195886 -0.9668539 0.3335778
plot.ts(y.dif2_2,lty=1)
points(y.dif2_2)
adf.test(y.dif2_1, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
## Warning in adf.test(y.dif2_1, alternative = c("stationary"), k =
## trunc((length(y) - : p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: y.dif2_1
## Dickey-Fuller = -5.594, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
Berdasarkan hasil differencing ordo 2 diperoleh kesimpulan bahwa data sudah stasioner dikarenakan nilai \(p-value = 0.01 < \alpha=0.05\) sehingga proses selanjutnya adalah mengidentifikasi kandidat model.
acf(y.dif2_2,lag.max = 100)
pacf(y.dif2_2,lag.max = 100)
eacf(y.dif2_2)
## AR/MA
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x x o o o o x x x o o o o o
## 1 x x 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 x o o o o o o o o o o o
## 4 x x x o x x o o o o o o o o
## 5 x x x o x x x o o o o o o o
## 6 x x x o o o o o o o o o o o
## 7 x x x x x o o x o o o o o o
Plot ACF menunjukkan cuts off setelah lag kedua dan plot PACF menunjukkan tails off. Sedangkan untuk plot EACF tanda silang mulai berhenti pada pertemuan angka 2 dengen 0, dan karena dilakukan differencing dua kali sehingga bisa disimpulkan model yang tepat adalah ARIMA(0,2,2) dengan \(p=0,d=2,q=2\).
set.seed(1234)
e2<-rnorm(200,0,1)
n2<-length(e2)
Model \(Y_{t}\) diperoleh dari penguraian operator backshift sehingga perlu dilakukan penguraian operator backshift terlebih dahulu untuk ARIMA(2,2,2)
\(\psi_{p}(1-B)^{d}Y_{t}=\mu +\theta_{q}(B)e_{t}\)
\(\psi_{2}(B)(1-B)^{2}Y_{t}=\mu +\theta_{2}(B)e_{t}\)
\((1-\psi_{1}B-\psi_{2}B^{2})(1-2B+B^{2})Y_{t}=\mu+(1-\theta_{1}(B)-\theta_{2}B^{2})e_{t}\)
\((1-2B+B^{2}-\psi_{1}B+2\psi_{1}B^{2}-\psi_{1}B^{3}-\psi_{2}B^{2}+2\psi_{2}B^{3}-\psi_{2}B^{4})Y_{t}=\mu+(1-\theta{1}B-\theta_{2}B^{2})+e_{t}\)
\(Y_{t}-2Y_{t-1}+Y_{t-2}-\psi_{1}Y_{t-1}+2\psi_{1}Y_{t-2}-\psi_{1}Y_{t-3}-\psi_{2}Y_{t-2}+2\psi_{2}Y_{t-3}-\psi_{2}Y_{t-4}=\mu+e_{t}-\theta_{1}e_{t-1}-\theta_{2}e_{t-2}\)
\(Y_{t}-(2+\psi_{1})Y_{t-1}-(\psi_{2}-2\psi_{1}-1)Y_{t-2}-(\psi_{1}-2\psi_{2})Y_{t-3}-\psi_{2}Y_{t-4}=\mu+e_{t}-\psi_{1}e_{t-1}-\theta_{2}e_{t-2}\)
\(Y_{t}=\mu+(2+\psi_{1})Y_{t-1}+(\psi_{2}-2\psi_{1}-1)Y_{t-2}+(\psi_{1}-2\psi_{2})Y_{t-3}+\psi_{2}Y_{t-4}+e_{t}-\psi_{1}e_{t-1}-\theta_{2}e_{t-2}\)
Setelah model \(Y_{t}\) diperoleh bisa dilakukan proses selanjutnya yaitu membangun model dari data yang telah dibangkitkan dan dibuang 25 data pertama sehingga menjadi 175 data terakhir yang digunakan.
#Membangun model ARIMA (2,2,2) dengan mu=0.15, psi1=0.55, psi2=-0.80, theta1=-0.35, theta2=-0.70 dan membuang 25 data pertama
mu2<-0.15
phi1<-0.55
phi2<--0.80
tetha12<--0.35
tetha22<-0.70
x<-c(1:n2)
for (i in 5:n2)
{x[i]<-mu+((2+phi1)*x[i-1])+((phi2-2*phi1-1)* x[i-2])+(phi1-2*phi2)*x[i-3]+
phi2*x[i-4]+e[i]-tetha12*e[i-1]-tetha22*e[i-2]}
x<-x[-c(1:25)]
Selanjutnya yaitu mengidentifikasi kestasioneran data dengan membuat time-series plot, correlogram, dan uji ADF
plot.ts(x,lty=1,ylab=expression(x[t]))
acf(x,lag.max = 20)
adf.test(x, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
## Warning in adf.test(x, alternative = c("stationary"), k = trunc((length(y) - :
## p-value greater than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: x
## Dickey-Fuller = 0.12151, Lag order = 5, p-value = 0.99
## alternative hypothesis: stationary
Berdasarkan pola dari plot data \(Y_{t}\) tidak membentuk pola yang stasioner. Kemudian untuk correlogram menunjukkan pola yang menurun secara perlahan hal tersebut mengindikasikan bahwa data tersebut tidak stasioner dan untuk uji ADF, karena nilai \(p-value = 0.99 >\alpha=0.05\) sehingga terima \(H_{0}\) yang artinya data tidak stasioner. Berdasarkan ketiga cara untuk menentukan kestasioneran, ketiganya memberikan kesimpulan bahwa data yang digunakan merupakan data yang tidak stasioner sehingga diperlukan proses pembedaan hingga data menjadi stasioner.
x.dif1<-diff(x,differences = 1)
plot.ts(x.dif1,lty=1)
points(x.dif1)
acf(x.dif1,lag.max = 20)
adf.test(x.dif1, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
## Warning in adf.test(x.dif1, alternative = c("stationary"), k = trunc((length(y)
## - : p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: x.dif1
## Dickey-Fuller = -4.1655, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
Berdasarkan hasil differencing ordo 1 diperoleh kesimpulan bahwa data belum stasioner dikarenakan plot acf terlihat menurun secara perlahan dan plot datanya masih menunjukkan adanya trend, walaupun nilai \(p-value = 0.01 < \alpha=0.05\). Supaya lebih meyakinkan, perlu dilakukan differencing ordo 2.
#Differencing ordo 2
#Cara 1
x.dif2_1<-diff(x,differences = 2)
head(x.dif2_1)
## [1] -0.3989602 1.6244108 -0.4217026 -0.9362163 1.5510166 1.4592066
plot.ts(x.dif2_1,lty=1)
points(x.dif2_1)
acf(x.dif2_1,lag.max = 20)
adf.test(x.dif2_1, alternative = c("stationary"),k=trunc((length(y)-1)^(1/3)))
## Warning in adf.test(x.dif2_1, alternative = c("stationary"), k =
## trunc((length(y) - : p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: x.dif2_1
## Dickey-Fuller = -9.7538, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
Berdasarkan hasil differencing ordo 2 diperoleh kesimpulan bahwa data sudah stasioner dikarenakan nilai \(p-value = 0.01 < \alpha=0.05\) dan plot acf serta plot datanya sudah menunjukkan data stasioner sehingga proses selanjutnya adalah mengidentifikasi kandidat model.
acf(x.dif2_1,lag.max = 20)
pacf(x.dif2_1,lag.max = 20)
eacf(x.dif2_1)
## AR/MA
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x x x x x o x o x x x x o o
## 1 x x x x x o x x x x x x x o
## 2 x x o x o o o o o o o o o o
## 3 x 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 o x x x x o o o o o o x o o
## 6 x x x x o o o o o o o o o o
## 7 x x o x o o o o o o o o o o
Plot ACF menunjukkan cuts off pada lag kedua, begitu pun dengan plot PACF. Sedangkan untuk plot EACF tanda silang mulai berhenti pada pertemuan angka 2 dengen 2, dan karena dilakukan differencing dua kali sehingga bisa disimpulkan model yang tepat adalah ARIMA(2,2,2) dengan \(p=2,d=2,q=2\).