-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path04-03-Forecast-ARIMA.Rmd
More file actions
41 lines (28 loc) · 1.04 KB
/
04-03-Forecast-ARIMA.Rmd
File metadata and controls
41 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## ARIMA Modeling {-}
```{r a1, comment=NA, warning=FALSE, message=FALSE, fig.width=9}
library(forecast)
# Generated Time Series
set.seed(1)
x = 100 + arima.sim(n = 100,
model = list(order = c(1, 1, 1), ar = .1, ma = .2))
# Plot the series
plot(x, main = "Simulated ARIMA(1,1,1)")
# Check if there is auto correlation, there is
Acf(x, main = "ACF"); Pacf(x, main = "PACF")
# How many differences does it take for the data to be stationary?
# 1
plot(diff(x), main = "First Order Difference")
# Check the Acf/Pacf with differences
Acf(diff(x), main = "ACF 1 diff") # One significant spike, suggests MA(1)
Pacf(diff(x), main = "PACF 1 diff") # One significant spike, indicates AR(1)
# Suggested model ARIMA(1,1,1)
mdl1 = arima(x, c(1,1,1))
# How do the ARMA terms compare with the terms used in the sim?
# AR1: .18 vs .1 in the sim
# MA1: .14 vs .2 in the sim
summary(mdl1)
# What does the forecast package auto.arima function suggest?
(mdl2 = auto.arima(x)) # No AR term
# How does the manual model compare with the auto.arima model?
AIC(mdl1, mdl2)
```