Marcel Dettling Institute for Data Analysis and Process Design - - PowerPoint PPT Presentation

marcel dettling
SMART_READER_LITE
LIVE PREVIEW

Marcel Dettling Institute for Data Analysis and Process Design - - PowerPoint PPT Presentation

Applied Time Series Analysis FS 2012 Week 03 Marcel Dettling Institute for Data Analysis and Process Design Zurich University of Applied Sciences marcel.dettling@zhaw.ch http://stat.ethz.ch/~dettling ETH Zrich, March 5, 2012 Marcel


slide-1
SLIDE 1

1

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Marcel Dettling

Institute for Data Analysis and Process Design Zurich University of Applied Sciences

marcel.dettling@zhaw.ch http://stat.ethz.ch/~dettling

ETH Zürich, March 5, 2012

slide-2
SLIDE 2

Descriptive Decomposition

It is convenient to describe non-stationary time series with a simple decomposition model = trend + seasonal effect + stationary remainder The modelling can be done with: 1) taking differences with appropriate lag (=differencing) 2) smoothing approaches (= filtering) 3) parametric models (= curve fitting)

2

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

t t t t

X m s E   

slide-3
SLIDE 3

3

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Parametric Modelling

When to use?  Parametric modelling is often used if we have previous knowledge about the trend following a functional form.  If the main goal of the analysis is forecasting, a trend in functional form may allow for easier extrapolation than a trend obtained via smoothing.  It can also be useful if we have a specific model in mind and want to infer it. Caution: correlated errors!

slide-4
SLIDE 4

4

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Parametric Modelling: Example

Maine unemployment data: Jan/1996 – Aug/2006

Unemployment in Maine

Time (%) 1996 1998 2000 2002 2004 2006 3 4 5 6

slide-5
SLIDE 5

5

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Modeling the Unemployment Data

Most often, time series are parametrically decomposed by using regression models. For the trend, polynomial functions are widely used, whereas the seasonal effect is modelled with dummy variables (= a factor). where Remark: choice of the polynomial degree is crucial!

2 3 4 1 2 3 4 ( ) t i t t

X t t t t E                 

   

1,2,...,128 ( ) 1,2,...,12 t i t  

slide-6
SLIDE 6

6

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Polynomial Order / OLS Fitting

Estimation of the coefficients will be done in a regression con-

  • text. We can use the ordinary least squares algorithm, but:
  • we have violated assumptions, is not uncorrelated
  • the estimated coefficients are still unbiased
  • standard errors (tests, CIs) can be wrong

Which polynomial order is required? Eyeballing allows to determine the minimum grade that is required for the polynomial. It is at least the number of maxima the hypothesized trend has, plus one.

t

E

slide-7
SLIDE 7

7

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Important Hints for Fitting

  • The main predictor used in polynomial parametric modeling

is the time of the observations. It can be obtained by typing time(maine).

  • For avoiding numerical and collinearity problems, it is

essential to center the time/predictors!

  • R sets the first factor level to 0, seasonality is thus

expressed as surplus to the January value.

  • For visualization: when the trend must fit the data, we have

to adjust, because the mean for the seasonal effect is usually different from zero!

slide-8
SLIDE 8

8

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Trend of O(4), O(5) and O(6)

Unemployment in Maine

Time (%) 1996 1998 2000 2002 2004 2006 3 4 5 6 O(4) O(5) O(6)

slide-9
SLIDE 9

9

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Residual Analysis: O(4)

Residuals vs. Time, O(4)

Time 1996 1998 2000 2002 2004 2006

  • 0.6
  • 0.2

0.2 0.6

slide-10
SLIDE 10

10

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Residual Analysis: O(5)

Residuals vs. Time, O(5)

Time 1996 1998 2000 2002 2004 2006

  • 0.6
  • 0.2

0.2 0.6

slide-11
SLIDE 11

11

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Residual Analysis: O(6)

Residuals vs. Time, O(6)

Time 1996 1998 2000 2002 2004 2006

  • 0.4
  • 0.2

0.0 0.2 0.4

slide-12
SLIDE 12

12

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Parametric Modeling: Remarks

Some advantages and disadvantages: + trend and seasonal effect can be estimated + and are explicitly known, can be visualised + even some inference on trend/season is possible + time series keeps the original length

  • choice of a/the correct model is necessary/difficult
  • residuals are correlated: this is a model violation!
  • extrapolation of

, are not entirely obvious

ˆ t m ˆt s ˆ t m ˆt s

slide-13
SLIDE 13

13

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Where are we?

For most of the rest of this course, we will deal with (weakly) stationary time series. They have the following properties:

  • If a time series is non-stationary, we know how to decompose

into deterministic and stationary, random part. Our forthcoming goals are:

  • understanding the dependency in a stationary series
  • modeling this dependency and generate forecasts

[ ]

t

E X  

2

( )

t

Var X   ( , )

t t h h

Cov X X 

slide-14
SLIDE 14

14

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Autocorrelation

The aim of this section is to explore the dependency structure within a time series. Def: Autocorrelation The autocorrelation is a dimensionless measure for the amount of linear association between the random variables collinearity between the random variables and .

( , ) ( , ) ( ) ( )

t k t t k t t k t

Cov X X Cor X X Var X Var X

  

 

t k

X 

t

X

slide-15
SLIDE 15

15

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Autocorrelation Estimation

Our next goal is to estimate the autocorrelation function (acf) from a realization of weakly stationary time series.

Luteinizing Hormone in Blood at 10min Intervals

Time lh 10 20 30 40 1.5 2.0 2.5 3.0 3.5 5 10 15

  • 0.2

0.2 0.6 1.0 ACF

Autocorrelation Function

slide-16
SLIDE 16

16

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Autocorrelation Estimation: lag k>1

Idea 1: Compute the sample correlation for all pairs (

, )

s s k

x x 

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+2}

k=2, cor=0.19

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+3}

k=3, cor=-0.15

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+4}

k=4, cor=-0.19

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+5}

k=5, cor=-0.16

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+6}

k=6, cor=-0.02

1.5 2.0 2.5 3.0 3.5 1.5 2.0 2.5 3.0 3.5 X_s X_{s+7}

k=7, cor=-0.01

1.5 2.0 2.5 3.0 1.5 2.0 2.5 3.0 3.5 X_s X_{s+8}

k=8, cor=0.01

1.5 2.0 2.5 3.0 1.5 2.0 2.5 3.0 3.5 X_s X_{s+9}

k=9, cor=-0.17

slide-17
SLIDE 17

17

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Autocorrelation Estimation: lag k

Idea 2: Plug-in estimate with sample covariance How does it work?  see blackboard…

slide-18
SLIDE 18

18

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Autocorrelation Estimation: lag k

Idea 2: Plug-in estimate with sample covariance where and

1

1 ˆ( ) ( )( )

n k s k s s

k x x x x n 

  

  

1

1

n t t

x x n

 

Standard approach in time series analysis for computing the acf

ˆ ( , ) ( ) ˆ( ) ˆ(0) ( )

t t k t

Cov X X k k Var X   

 

slide-19
SLIDE 19

19

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Comparison Idea 1 vs. Idea 2

 see blackboard for some more information

10 20 30 40

  • 1.0
  • 0.5

0.0 0.5 1.0 lag acf

Comparison between lagged sample correlations and acf

acf lagged sample correlations

slide-20
SLIDE 20

20

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

What is important about ACF estimation?

  • Correlations are never to be trusted without a visual

inspection with a scatterplot.

  • The bigger the lag k, the fewer data pairs remain for

estimating the acf at lag k.

  • Rule of the thumb: the acf is only meaningful up to about

a) lag 10*log10(n) b) lag n/4

  • The estimated sample ACs can be highly correlated.
  • The correlogram is only meaningful for stationary series!!!
slide-21
SLIDE 21

21

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Correlogram

A useful aid in interpreting a set of autocorrelation coefficients is the graph called correlogram, where the are plotted against the lag k. Interpreting the meaning of a set of autocorrelation coefficients is not always easy. The following slides offer some advice.

ˆ( ) k 

5 10 15

  • 0.2

0.2 0.6 1.0 Lag ACF

Series lh

slide-22
SLIDE 22

22

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Random Series – Confidence Bands

If a time series is completely random, i.e. consists of i.i.d. random variables , the (theoretical) autocorrelations are equal to 0. However, the estimated are not. We thus need to decide, whether an observed is significantly so, or just appeared by chance. This is the idea behind the confidence bands.

ˆ( ) k 

5 10 15

  • 0.2

0.2 0.6 1.0 Lag ACF

Series lh

t

X ( ) k  ˆ( ) k  

slide-23
SLIDE 23

23

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Random Series – Confidence Bands

For long i.i.d. time series, it can be shown that the are approximately distributed. Thus, if a series is random, 95% of the estimated can be expected to lie within the interval

ˆ( ) k  ˆ( ) k 

2 / n 

5 10 15 20 0.0 0.4 0.8 Lag ACF

i.i.d. Series with n=300

 

0,1/ N n

slide-24
SLIDE 24

24

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Random Series – Confidence Bands

Thus, even for a (long) i.i.d. time series, we expect that 5% of the estimated autocorrelation coeffcients exceed the confidence

  • bounds. They correspond to type I errors.

Note: the probabilistic properties of non-normal i.i.d series are much more difficult to derive.

5 10 15 20 0.0 0.4 0.8 Lag ACF

i.i.d. Series with n=300

slide-25
SLIDE 25

25

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Short Term Correlation

Simulated Short Term Correlation Series

Time ts.sim 100 200 300 400

  • 4
  • 2

2 5 10 15 20 25

  • 0.2

0.2 0.6 1.0 Lag ACF

ACF of Simulated Short Term Correlation Series

slide-26
SLIDE 26

26

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Short Term Correlation

Stationary series often exhibit short-term correlation, characterized by a fairly large value of , followed by a few more coefficients which, while significantly greater than zero, tend to get successively

  • smaller. For longer lags k, they are close to 0.

A time series which gives rise to such a correlogram, is one for which an observation above the mean tends to be followed by one

  • r more further observations above the mean, and similarly for
  • bservations below the mean.

A model called an autoregressive model may be appropriate for series of this type.

ˆ(1) 

slide-27
SLIDE 27

27

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Alternating Time Series

Simulated Alternating Correlation Series

Time ts.sim 50 100 150 200

  • 3
  • 1

1 2 3 5 10 15 20

  • 0.5

0.0 0.5 1.0 Lag ACF

ACF of Simulated Alternating Correlation Series

slide-28
SLIDE 28

28

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Non-Stationarity in the ACF: Trend

Simulated Series with a Trend

Time ts.sim 50 100 150 200 5 15 25 5 10 15 20 0.0 0.4 0.8 Lag ACF

ACF of Simulated Series with a Trend

slide-29
SLIDE 29

29

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Non-Stationarity in the ACF: Seasonal Pattern

De-Trended Mauna Loa Data

Time diff(co2) 1960 1970 1980 1990

  • 2
  • 1

1 2 0.0 0.5 1.0 1.5 2.0

  • 0.5

0.0 0.5 1.0 Lag ACF

ACF of De-Trended Mauna Loa Data

slide-30
SLIDE 30

30

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

ACF of the Raw Airline Data

Airline Data

Time airline 1950 1952 1954 1956 1958 1960 100 300 500 0.0 0.5 1.0 1.5

  • 0.2

0.2 0.6 1.0 Lag ACF

ACF of Airline Data

slide-31
SLIDE 31

31

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Outliers and the ACF

Outliers in the time series strongly affect the ACF estimation!

Beaver Body Temperature

Time beav1$temp 20 40 60 80 100 36.4 36.6 36.8 37.0 37.2 37.4

slide-32
SLIDE 32

32

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Outliers and the ACF

36.4 36.6 36.8 37.0 37.2 37.4 36.4 36.6 36.8 37.0 37.2 37.4

Lagged Scatterplot with k=1 for Beaver Data

1 Outlier, appears 2x in the lagged scatterplot

slide-33
SLIDE 33

33

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Outliers and the ACF

The estimates are very sensitive to outliers. They can be diagnosed using the lagged scatterplot, where every single outlier appears twice. Strategy for dealing with outliers:

  • if it is an outlier: delete the observation
  • replace the now missing observations by either:

a) global mean of the series b) local mean of the series, e.g. +/- 3 observations c) fit a time series model and predict the missing value

ˆ( ) k 

slide-34
SLIDE 34

34

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

General Remarks about the ACF

a) Appearance of the series => Appearance of the ACF Appearance of the series <= Appearance of the ACF b) Compensation All autocorrelation coefficients sum up to -1/2. For large lags k, they can thus not be trusted, but are at least

  • damped. This is a reason for using the rule of the thumb.

1 1

1 ˆ( ) 2

n k

k 

 

 

slide-35
SLIDE 35

35

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

ACF vs. Lagged Sample Correlations

10 20 30 40

  • 1.0
  • 0.5

0.0 0.5 1.0 lag acf

Comparison between lagged sample correlations and acf

acf lagged sample correlations

slide-36
SLIDE 36

36

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

How Well Can We Estimate the ACF?

What do we know already?

  • The ACF estimates are biased
  • At higher lags, we have few observations, and thus variability
  • There also is the compensation problem…

 ACF estimation is not easy, and interpretation is tricky. For answering the question above:

  • For an AR(1) time series process, we know the true ACF
  • We generate a number of realizations from this process
  • We record the ACF estimates and compare to the truth
slide-37
SLIDE 37

37

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

Theoretical vs. Estimated ACF

50 100 150 200 0.0 0.2 0.4 0.6 0.8 1.0 lag ACF

True ACF of AR(1)-process with alpha_1=0.7

50 100 150 200

  • 0.2

0.2 0.6 1.0 Lag ACF

Estimated ACF from an AR(1)-series with alpha_1=0.7

slide-38
SLIDE 38

38

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

How Well Can We Estimate the ACF?

A) For AR(1)-processes we understand the theoretical ACF B) Repeat for i=1, …, 1000 Simulate a length n AR(1)-process Estimate the ACF from that realization End for C) Boxplot the (bootstrap) sample distribution of ACF-estimates Do so for different lags k and different series length n

slide-39
SLIDE 39

39

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

How Well Can We Estimate the ACF?

Variation in ACF(1) estimation

n=20 n=50 n=100 n=200

  • 1.0
  • 0.5

0.0 0.5 1.0

slide-40
SLIDE 40

40

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

How Well Can We Estimate the ACF?

Variation in ACF(2) estimation

n=20 n=50 n=100 n=200

  • 1.0
  • 0.5

0.0 0.5 1.0

slide-41
SLIDE 41

41

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

How Well Can We Estimate the ACF?

Variation in ACF(5) estimation

n=20 n=50 n=100 n=200

  • 1.0
  • 0.5

0.0 0.5 1.0

slide-42
SLIDE 42

42

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

How Well Can We Estimate the ACF?

Variation in ACF(10) estimation

n=20 n=50 n=100 n=200

  • 1.0
  • 0.5

0.0 0.5 1.0

slide-43
SLIDE 43

43

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2010 – Week 03

Trivia ACF Estimation

  • In short series, the ACF is strongly biased. The consistency

kicks in and kills the bias only after ~100 observations.

  • The variability in ACF estimation is considerable. We observe

that we need at least 50, or better, 100 observations.

  • For higher lags k, the bias seems a little less problematic, but

the variability remains large even with many observations n.

  • The confidence bounds, derived under independence, are

not very accurate for (dependent) time series.  Interpreting the ACF is tricky!

slide-44
SLIDE 44

44

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Application: Variance of the Arithmetic Mean

Practical problem: we need to estimate the mean of a realized/

  • bserved time series. We would like to attach a standard error.
  • If we estimate the mean of a time series without taking into

account the dependency, the standard error will be flawed.

  • This leads to misinterpretation of tests and confidence

intervals and therefore needs to be corrected.

  • The standard error of the mean can both be over-, but also
  • underestimated. This depends on the ACF of the series.

 For the derivation, see the blackboard…

slide-45
SLIDE 45

45

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Partial Autocorrelation Function (PACF)

The kth partial autocorrelation coefficient is defined as the correlation between the random variables and , given all the values in between. Their meaning is best understood by drawing an analogy to simple and multiple linear regression. The ACF measures the „simple“ dependence between and , whereas the PACF measures that dependence in a „multiple“ fashion.

( )

part k

t

X

t k

X 

1 1 1 1

( ) ( , | ,..., )

part t k t t t t k t k

k Cor X X X x X x 

      

  

t k

X 

t

X

slide-46
SLIDE 46

46

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Facts about the PACF

  • Estimation of the PACF is complicated and will not be

discussed in the course. R can do it ;-)

  • The first PACF coefficient is equal to the first ACF
  • coefficient. Subsequent coefficients are not equal, but can

be derived from each other.

  • For a time series generated by an AR(p)-process, the pth

PACF coefficient is equal to the pth AR-coefficient. All PACF coefficients for lags k>p are equal to 0.

  • Confidence bounds also exist for the PACF.
slide-47
SLIDE 47

47

Marcel Dettling, Zurich University of Applied Sciences

Applied Time Series Analysis

FS 2012 – Week 03

Outlook to AR(p)-Models

Suppose that Zt is an i.i.d random process with zero mean and variance . Then a random process Xt is said to be an auto- regressive process of order p if This is similar to a multiple regression model, but Xt is regressed not on independent variables, but on past values of itself. Hence the term auto-regressive. We use the abbreviation AR(p).

2 Z

1 1

...

t t p t p t

X X X Z  

 

   