ar, ma, arma examples in r - max planck societytimeseries/presentations/andres.pdf · time series...

15

Upload: dodan

Post on 30-Apr-2018

217 views

Category:

Documents


1 download

TRANSCRIPT

AR, MA, ARMA Examples in R

June 10, 2009

1

The R Time Series Package: tseries

� Version 0.10-18, 2009-02-05

� Adrian Trapletti, Kurt Hornik

� Package for time series analysis and computational �nance

� Available at any CRAN Mirror: http://www.r-project.org/

2

Sample AR(1) Processes

Two processes,

Xt = aXt−1 + εt

a = ±0.9, σε = 1

R (r) = σ2ε .

a|r|

(1− a2)

ρ (r) =R (r)R (0)

= a|r|

(script1.R, script2.R)

3

Sample MA(1) Process

Xt = εt + bεt−1

R(r) =

(1 + b2

)σ2

ε r = 0bσ2

ε r = 10 r > 1

ρ(r) ={ b

(1+b2) r = 10 r > 1

When b = 0.5,ρ (1) = 0.4 and when b = −0.5,ρ (1) = −0.4(script4.R, script5.R)

4

ACF and PACF Criterion

The Autocorrelation Function (ACF) does not tells us much about theorder of AR and ARMA. For example the AR(1) model Xt = aXt + εt

R (2) = cov (Xt, Xt−2) = cov (aXt + εt, Xt−2)

= cov (a²Xt−2 + aεt−1 + εt, Xt−2) = a2R (0)

Not zero, Xt is dependent on Xt−2through Xt−1.We can removethis dependence by considering the correlation between Xt− aXt−1 andXt−2 − aXt−1. Then,

cov (Xt − aXt−1, Xt−2 − aXt−1) = cov (εt, Xt−2 − aXt−1) = 0

5

ACF and PACF Criterion

(script6.R : Sample AR(2) model ACF)

6

El Niño and Fish Population

Estimate of new �sh in a region of the paci�c under the in�uence ofEl Niño.

(script7.R)

7

Lynx Captured in North-West Canada

Amplitude variations: noise or pseudo-periodic ARMA process?(script8.R)

8

Canadian Lynx

9

AR Residuals STD

1 0.34118302 0.22824403 0.22757554 0.22359785 0.22230376 0.22213287 0.21637328 0.21254499 0.211340610 0.206546311 0.192169412 0.1852098

(a)

ARMA Residuals STD

1,1 0.26399982,2 0.22480923,3 0.20956774,4 0.4146432

(b)

10

Estimation (AR)

� Least squares.

� Yule-Walker. Parameter estimation by �tting to the sample auto-covariance (or autocorrelation) function.

� Exact likelihood function. LS but consider the initial observationsX1, . . . , Xk

Estimation (MA)

� Box-Jenkins iterative method. {εt}is determined recursively.

� Exact likelihood function

Estimation (ARMA)

� Exact likelihood function, Ljung, Box, Walker, Revfeim

11

Order of the model

� Partial autocorrelation function

� Residual variance plots

� Akaike criteria

� Visual inspection of the ACF

12

Time Series Analysis and Its ApplicationsWith R Examples

Shumway, Robert H., Sto�er, David S. 2nd ed., 2006.

13

Non-causal AR model

The random walk,Xt = aXt−1 + εt

a = 1

Is not stationary. A stationary model can be created if we write Xt+1 =aXt + εt+1

Xt =a−1Xt+1 − a−1εt+1

=a−1(a−1Xt+2 − a−1εt+2

)+ a−1εt+1

...

=a−kXt+k −k−1∑j=1

a−jεt+j

as |a|−1< 0 the process is stationary, but future dependent.

(script3.R)

14

ACF Criterion (Maybe also PACF)

The autocorrelation function for an AR(p) model has the form

ρ (r) = B1µ|r|1 +B2µ

|r|2 + . . .+Bkµ

|r|k

where Bi are constants determined by by the boundary conditionsand µi are the roots of the general order process polynomial.

� For the model to be stationary all the roots |µi| < 1

� If all µi are real ρ (r) decays exponentially

� If a pair are complex then there are oscillations

(script6.R : Sample AR(2) model ACF)

15