Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Time Series

Lecture 3: Trend

Semester 6A
Program Studi Matematika
Fakultas Sains dan Teknologi
UIN Syarif Hidayatullah Jakarta
2015/2016

Time series model

Stationary model

Non-stationary model

Deterministic vs. stochastic trend


Let us consider two of the simplest versions:

Deterministic trend (DT):

= +

Stochastic trend (ST):

= + 1 +

where ~ 0, 2 .

Deterministic vs. stochastic trend


Let us consider two of the simplest versions:

Deterministic trend (DT):

= +

Stochastic trend (ST):

= + 1 +

where ~ 0, 2 .
It is easy to see that

= =
but
= 2 and = 2

Simulated DT and ST time series

60
40
20
0

y(t)

80

100

120

y(t) = 0.5*t + e
y(t) = 0.5 + y(t-1) + e

50

100
Time

150

200

Simulated DT and ST time series

20

40

y(t)

60

80

y(t) = 0.5*t + e
y(t) = 0.5 + y(t-1) + e

50

100
t

150

200

Simulated DT and ST time series (R Code)


##stochastic time trend
yt <- c(1:200)*0
e <- rnorm(200)
yt <- e + yt
for (i in 2:200) {
yt[i] <- 0.5 + yt[i - 1] + e[i]
}
yt <- ts(yt)
plot(yt, type = "l", col = "red", ylab = "y(t)")
for (j in 1: 100) {
yt <- c(1:200)*0
e <- rnorm(200)
yt <- e + yt
for (i in 2:200) {
yt[i] <- 0.5 + yt[i - 1] + e[i]
}
lines(yt, type = "l", col = "red")
}
##deterministic time trend
t <- c(1:200)
beta <- 0.5
yt <- beta*t + rnorm(100)
for (j in 1:100) {
yt <- beta*t + rnorm(100)
lines(t,yt, type = "l")
}

Deterministic trend

Linear deterministic trend:


= 0 + 1 +

Quadratic deterministic trend:

= 0 + 1 + 2 2 +

In general:
= +

The mean is time dependent, but the variance is constant, can


be any stationary series (does not have to be a white noise).

Regression Analysis

Consider the following linear deterministic trend:


= 0 + 1 +

The classical least square (or regression) method is to choose


an estimates of 0 and 1 values that minimizes:

0 , 1 =

0 + 1
=1

We find that:
1 =

=1

=1

0 = 1
where =

+1
2

is the average of 1,2, ,

Example 1

Consider a time series data with random walk process.


Suppose we (mistakenly) treat this as a linear time trend:
= 0 + 1 +
Generate and fit the data in R:

library(TSA)
data(rwalk)
plot(rwalk, type = "o")
model1 <- lm(rwalk~time(rwalk))
summary(model1)

2
0
-2

>
>
>
>
>

10

20

30
Time

40

50

60

Example 1

R Output:

Example 1
R Output:

= 1.01 + 0.13

-2

Fitting a line to these data


is not appropriate!

10

20

30

40

50

60

Example 2

Consider now modeling and estimating seasonal trends, such


as the average monthly temperature data. Here we assume that
the observed series can be represented as
= +
where E = 0 for all

10

20

30

40

50

60

70

The most general assumption for is (seasonal means model)

Temperature

1964

1966

1968

1970
Time

1972

1974

1976

Example 2 (fit a model without an intercept term)

R Code:
>
>
>
>

data(tempdub)
month. <- season(tempdub) # period added to improve table display
model2 <- lm(tempdub ~ -1 + month.) # -1 removes the intercept term
summary(model2)

R Output:

Example 2 (fit a model with an intercept term)

R Code:
> model3 <- lm(tempdub ~ month.) # January is dropped automatically
> summary(model3)

R Output:

Reliability and efficiency of regression estimates

Assuming that the series can be represented as = +


where is a deterministic trend and is a zero-mean
stationary process with autocovariance and autocorrelation .
If = 0 + 1 , then the least square estimate of the slope:
1 =

=1

2
=1

And the estimate variance of the slope, where 1 0 but = 0,


> 1:
120
3
(1 ) =
1 + 21 1
2
( 1)

For large :
120 (1 + 21 )
(1 ) =
(2 1)

Reliability and efficiency of regression estimates

If is a white noise:
1

120 1 + 21
120
=
=
2
( 1)
(2 1)

If is a moving average process with 1 = 0.4:


1

120 1 + 21
120 (0.2)
=
=
2
( 1)
(2 1)

the variance of 1 is only 20% of what it would be if is


a white noise.

If 1 > 0, then 1 would be larger than for white noise.


The OLS estimates can be used to estimate the unknown
parameters in the trend function, but the estimated standard
deviation may not be correct.

Interpreting regression output

Consider the time series = + , where is a linear time


trend:
= 0 + 1

For each , the unobserved stochastic component can be


estimated (predicted) by
If the process has constant variance, then the standard
deviation of (residual standard deviation):

=1

where is the number of parameters estimated in and


is the degrees of freedom for .

Interpreting regression output

is an absolute measure of the goodness of fit of the estimated


trend the smaller the value of , the better the fit.
Another measure of the goodness of fit is the coefficient
determination, 2 - the square of the sample correlation
coefficient between the observed series and the estimated
trend.

Interpreting regression output

R output:

81% of the variation in the random walk series is explained by


the linear time trend.
The standard deviation of the coefficients (Std. Error) are
appropriate when the stochastic component is white noise.
t-values = estimate / std. error are only appropriate if the
stochastic component is normally distributed white noise.

Residual analysis

The unobserved stochastic component can be estimated


(predicted) by the residual
=

We call the residual corresponding to the th observation.


If the trend model is reasonably correct, then the residuals
should behave roughly like the true stochastic component, and
various assumptions about the stochastic component can be
assessed by looking at the residuals.

Example: Seasonal Model


R Code:

-2

-1

> plot(y=rstudent(model3),x=as.vector(time(tempdub)), xlab='Time',ylab='Standardized


Residuals',type='o')

Standardized Residuals

1964

1966

1968

1970
Time

1972

1974

1976

Example: Seasonal Model


R Code:
> plot(y=rstudent(model3),x=as.vector(time(tempdub)),xlab='Time', ylab='Standardized
Residuals',type='l')
> points(y=rstudent(model3),x=as.vector(time(tempdub)), pch=as.vector(season(tempdub)))

-2

-1

Standardized Residuals

J
JO
F O
M
D
S
JM N
A
F
M
N M
A
A
D
DJ
A A
A
J
J M
A
O A
M J D AO
S
S
J
N
A
S
AJ
D
A M S JJ
J
N
NF
J J
D
N J
S J J O J SN J S F J S
AJ
N
F
O
O
F
JN
M
F
AJAS
AO
F
MJJ A
A
M AO F
JO
M
A
A
N
M
M DJM D
M
A
D MJ S
O
N
D
J JF N
S
MA
M
O
A
J
J
F
J
D
M
J
M

FM

1964

1966

1968

1970
Time

1972

1974

1976

Example: Seasonal Model


R Code:
> plot(y=rstudent(model3),x=as.vector(fitted(model3)), xlab='Fitted Trend Values',
ylab='Standardized Residuals',type='n')
> points(y=rstudent(model3),x=as.vector(fitted(model3)), pch=as.vector(season(tempdub)))

-1

J
J
J
J
J
J
J
J

-2

Standardized Residuals

J
J

D
F
F
F
F
F
F
F

D
D
D
D
D

D
D
D

M
M
M
M
M

O
O

N
N
N
N
N
N
N
N
N
N

A
A
A
A
A
A
A
A
A
A

O
O
O
O
O
O
O

M
M
S
M
M
S
M S
S
S
S
M
M
M S
M S
M

J
A
A
J
J
A
J
A
J
A J
J
J
J
J A
A J
J
A J
J A J
J

M
M

J
20

30

40

50

Fitted Trend Values

60

70

Example: Seasonal Model

R Code:
> hist(rstudent(model3),xlab='Standardized Residuals, main = )
> qqnorm(rstudent(model3))
> shapiro.test(rstudent(model3))

1
0
-2

-1

Sample Quantiles

20
15
10
5
0

Frequency

25

30

35

Normal Q-Q Plot

-3

-2

-1

Standardized Residuals

-2

-1

Theoretical Quantiles

Example: Seasonal Model


Sample autocorrelation function, , at lag as

R Code:

-0.15

-0.05

ACF

0.05

0.15

> acf(rstudent(model3))

10

15
Lag

20

Example: Random Walk Process


R Output:

= 1.01 + 0.13

-2

10

20

30

40

50

60

Example: Random Walk Process

Residual plots:

1
0
-1
-2

Standardized Residuals

> plot(y=rstudent(model1),x=as.vector(time(rwalk)), ylab='Standardized


Residuals',xlab='Time',type='o')

10

20

30

40

50

60

time
The plot is too smooth and hang
together too much for white
noise.

Example: Random Walk Process

Residual plots:

0
-1
-2

residuals

> plot(y=rstudent(model1),x=fitted(model1), ylab='Standardized Residuals',xlab='Fitted Trend


Line Values', type='p')

fitted trend line values

Similar pattern! Larger residuals associated with larger fitted


values.

Example: Random Walk Process

Check for normality:

Normal Q-Q Plot

0
-1

8
6
4

-2

2
0

Frequency

10

Sample Quantiles

12

14

Histogram of rstudent(model)

-3

-2

-1

rstudent(model)

-2

-1

0
Theoretical Quantiles

Example: Random Walk Process


Sample autocorrelation of residuals:

0.2

0.4

0.6

Series rstudent(model)

-0.4

-0.2

0.0

ACF

10
Lag

15

Example: Wages Data

Example: Wages Data

8.0

8.5

9.0

9.5

Plot of wages data over time

Wages

1982

1983

1984

1985
Time

1986

1987

Example: Wages Data

8.0

8.5

9.0

9.5

Fit a linear trend to wages data:

Wages

1982

1983

1984

1985
Time

1986

1987

Example: Wages Data

-3

-2

-1

Residual plot:

standardized residuals

10

20

30

40
Index

50

60

70

Example: Wages Data


Sample autocorrelation of residuals:

-0.2

0.0

0.2

0.4

0.6

0.8

Series r

ACF

10
Lag

15

You might also like