18
ARIMA MODELING WITH R ARIMA - Integrated ARMA

ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

  • Upload
    others

  • View
    37

  • Download
    1

Embed Size (px)

Citation preview

Page 1: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

ARIMA - Integrated ARMA

Page 2: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Identifying ARIMA● A time series exhibits ARIMA behavior if the differenced

data has ARMA behavior> # Simulation ARIMA(p = 1, d = 1, q = 0)

> x <- arima.sim(list(order = c(1, 1, 0), ar = .9), n = 200) > plot(x, main = "ARIMA(p = 1, d = 1, q = 0)") > plot(diff(x), main = "ARMA(p = 1, d = 0, q = 0)")

ARMA(p = 1, d = 0, q = 0)

Time

diff(x)

0 50 100 150 200

−4−2

02

4ARIMA(p = 1, d = 1, q = 0)

Time

x

0 50 100 150 200

−100

−50

0

Page 3: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Identifying ARIMA● A time series exhibits ARIMA behavior if the differenced

data has ARMA behavior> # Simulation ARIMA(p = 1, d = 1, q = 0)

> x <- arima.sim(list(order = c(1, 1, 0), ar = .9), n = 200) > plot(x, main = "ARIMA(p = 1, d = 1, q = 0)") > plot(diff(x), main = "ARMA(p = 1, d = 0, q = 0)")

ARIMA(p = 1, d = 1, q = 0)

Time

x

0 50 100 150 200

−200

−100

0

ARMA(p = 1, d = 0, q = 0)

Time

diff(x)

0 50 100 150 200

−6−4

−20

24

6

Page 4: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Identifying ARIMA● A time series exhibits ARIMA behavior if the differenced

data has ARMA behavior> # Simulation ARIMA(p = 1, d = 1, q = 0)

> x <- arima.sim(list(order = c(1, 1, 0), ar = .9), n = 200) > plot(x, main = "ARIMA(p = 1, d = 1, q = 0)") > plot(diff(x), main = "ARMA(p = 1, d = 0, q = 0)")

ARIMA(p = 1, d = 1, q = 0)

Time

x

0 50 100 150 200

−200

−100

−50

0

ARMA(p = 1, d = 0, q = 0)

Time

diff(x)

0 50 100 150 200

−6−4

−20

24

6

Page 5: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

ACF and PCF of an Integrated ARMA> x <- arima.sim(list(order = c(1, 1, 0), ar = .9), n = 200) > acf2(x)

5 10 15 20 25

0.0

0.4

0.8

Series: x

LAG

ACF

5 10 15 20 25

0.0

0.4

0.8

LAG

PACF

Page 6: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

ACF and PCF of a Differenced ARIMA> x <- arima.sim(list(order = c(1, 1, 0), ar = .9), n = 200) > acf2(diff(x))

5 10 15 20 25

−0.2

0.2

0.6

1.0

Series: diff(x)

LAG

ACF

5 10 15 20 25

−0.2

0.2

0.6

1.0

LAG

PACF

Indicates an AR(1) for the differenced data

Page 7: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Weekly Oil PricesTails

Tails

● Looks like ARIMA(1, 1, 1)

Random Walk

Stationary

Page 8: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

Let’s practice!

Page 9: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

ARIMA Diagnostics

Page 10: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Weekly Oil Prices ARIMA(1, 1, 1)?

Page 11: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Weekly Oil Prices ARIMA(1, 1, 1)?> oil <- window(oil, end = 2006) > x <- sarima(oil, p = 1, d = 1, q = 1) > x$ttable

Estimate SE t.value p.value ar1 -0.4987 0.0995 -5.0131 0.0000 ma1 0.7316 0.0734 9.9732 0.0000 constant 0.1091 0.0936 1.1664 0.2443

Page 12: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Weekly Oil Prices ARIMA(1, 1, 1)!Standardized Residuals

Time

2000 2001 2002 2003 2004 2005 2006

−4−2

01

2

0.0 0.1 0.2 0.3 0.4 0.5

−0.2

0.0

0.2

0.4

0.6

ACF of Residuals

LAG

ACF

−3 −2 −1 0 1 2 3

−4−2

01

2

Normal Q−Q Plot of Std Residuals

Theoretical Quantiles

Sam

ple

Qua

ntile

s

5 10 15 20

0.0

0.2

0.4

0.6

0.8

1.0

p values for Ljung−Box statistic

lag

p va

lue

Page 13: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Overfit: ARIMA(2, 1, 1) and ARIMA(1, 1, 2)> oil_fit1 <- sarima(oil, p = 2, d = 1, q = 1) > oil_fit1$ttable

Estimate SE t.value p.value ar1 -0.4704 0.1117 -4.2121 0.0000 ar2 -0.0738 0.0652 -1.1319 0.2586 ma1 0.6771 0.0986 6.8696 0.0000 constant 0.1088 0.0878 1.2391 0.2163

> oil_fit2 <- sarima(oil, p = 1, d = 1, q = 2) > oil_fit2$ttable

Estimate SE t.value p.value ar1 -0.3664 0.1816 -2.0178 0.0445 ma1 0.5777 0.1818 3.1777 0.0016 ma2 -0.0836 0.0837 -0.9989 0.3186 constant 0.1088 0.0884 1.2306 0.2194

Page 14: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

Let’s practice!

Page 15: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

Forecasting ARIMA

Page 16: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Forecasting ARIMA Processes● The model describes how the dynamics of the time

series behave over time

● Forecasting simply continues the model dynamics into the future

● Use sarima.for() to forecast in the astsa-package

Page 17: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA Modeling with R

Forecasting ARIMA Processes> oil <- window(astsa::oil, end = 2006) > oilf <- window(astsa::oil, end = 2007) > sarima.for(oil, n.ahead = 52, 1, 1, 1) > lines(oilf)

Time

oil

2004.0 2004.5 2005.0 2005.5 2006.0 2006.5 2007.0

4050

6070

8090

Page 18: ARIMA - Integrated ARMA · ARIMA Modeling with R Identifying ARIMA A time series exhibits ARIMA behavior if the differenced data has ARMA behavior > # Simulation ARIMA(p = 1,

ARIMA MODELING WITH R

Let’s practice!