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
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
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)")

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 <- ts_arima
acf(diff1)

pacf(diff1)

adf.test(diff1)
##
## Augmented Dickey-Fuller Test
##
## data: diff1
## Dickey-Fuller = -2.449, Lag order = 5, p-value = 0.388
## alternative hypothesis: stationary
auto.arima(diff1)
## Series: diff1
## 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
data.ts <- ts(diff1)
head(data.ts)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] 0.0000000 -0.4362295 -1.5730181 -2.0528332 -3.3057208 -4.3986311
acf(data.ts)

pacf
## function (x, lag.max, plot, na.action, ...)
## UseMethod("pacf")
## <bytecode: 0x0000018fa5d926e0>
## <environment: namespace:stats>
eacf(data.ts)
## AR/MA
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x x x x x x x x x x x x x x
## 1 x o x o o o o o o o o o o o
## 2 x o x 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 x o o o o o o o o o o o
## 5 x x x o o o o o o o o o o o
## 6 x x o o x o o o o o o o o o
## 7 x x x x x x o o o o o o o o
auto.arima(data.ts)
## Series: data.ts
## 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.6864 -0.5620
## s.e. 0.2329 0.2631
##
## sigma^2 estimated as 0.8813: log likelihood = -271.18, aic = 546.35
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.7510 0.9192 0.1351 0.1413
## s.e. 0.1286 0.1449 0.0933 0.0817
##
## sigma^2 estimated as 0.8451: log likelihood = -267.19, aic = 542.37
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.1368
## s.e. 0.0702
##
## sigma^2 estimated as 0.8895: log likelihood = -272.09, aic = 546.18
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
## 1e-04 0.9999 1.2110 0.2111 -2.5715
## s.e. 0e+00 0.0000 0.0704 0.0703 21921.3054
##
## sigma^2 estimated as 0.8899: log likelihood = -273.94, aic = 557.88