Time Series Analysis Parte 1 PDF
Time Series Analysis Parte 1 PDF
1 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
2 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
10
5
0
Time
3 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
2000
1000
0
Time
4 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
3000
2000
1000
0
Time
5 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
400
300
200
100
Time
6 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
−0.05
−0.10
−0.15
Time
7 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
8 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
10 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
11 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
12 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
Xt = Tt + St + It
Xt = Tt × St × It
Time
14 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
18 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
18
●
●
16
● ● ●
● ●
●
●
14
●
12
●
original series
● MA(m=3)
MA (m=4)
10
Time
20 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
21 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
22 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
23 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
24 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
25 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
26 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
27 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
Xt = µt + t ,
β̂1 =
Year Qtr Revenue Xt? t tXt? t2
1992
1992
1
2
1026.00
1056.00
1440.2
1494.4
1
2
1440.2
2988.8
1
4
451804.8 − 20( 210 39423.4
20 )( 20 )
1992
1992
3
4
1182.00
2861.00
1598.5
1553.6
3
4
4795.5
6214.4
9
16 2870 − 20( 210
20 )
2
1993 1 1172.00 1645.1 5 8225.5 25
1993 2 1249.00 1767.6 6 10605.6 36
1993 3 1346.00 1820.3 7 12742.1 49 = 56.93,
1993 4 3402.00 1847.4 8 14779.2 64
1994 1 1286.00 1805.1 9 16245.9 81
1994 2 1317.00 1863.8 10 18638.0 100
1994 3 1449.00 1959.6 11 21555.6 121 β̂0 =
1994 4 3893.00 2114.0 12 25368.0 144
1995 1 1462.00 2052.2 13 26678.6 169
1995 2 1452.00 2054.9 14 28768.6 196 39423.4 210
1995 3 1631.00 2205.7 15 33085.5 225 −56.931( )
1995 4 4200.00 2280.7 16 36491.2 256 20 20
1996 1 1776.25 2493.3 17 42386.1 289
1996 2 1808.25 2559.0 18 46062.0 324
1996 3 1941.75 2626.0 19 49894.0 361 = 1373.39,
1996 4 4128.75 2242.0 20 44840.0 400
Sum - - 39423.4 210 451804.8 2870 regression line to
deseasonalized data:
Coefficients:
(Intercept) t
1373.39 56.93
32 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
●
●
2500
●
deseasonalized revenue
●
●
●
●
2000
● ●
● ●
● ●
●
●
●
1500
●
●
●
1000
0 5 10 15 20
time
33 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
●
●
4000
●
Toys R US revenue
●
3000
●
2000
●
● ●
●
● ● ●
● ●
● ●
● ●
1000
● ●
Year
35 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
36 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
37 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
or equivalently,
X̂t+1 = αXt + (1 − α)X̂t ,
where 0 < α < 1 is the exponentially weighted moving average
(referred to as the smoothing parameter).
40 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
For α = 0.2: X̂t+1 = 0.2Xt + 0.8X̂t . For α = 0.4: X̂t+1 = 0.4Xt + 0.6X̂t .
X̂1 = X1 = 39 X̂1 = X1 = 39
X̂2 = 0.2(39) + 0.8(39) = 39 X̂2 = 0.4(39) + 0.6(39) = 39
X̂3 = 0.2(44) + 0.8(39) = 40 X̂3 = 0.4(44) + 0.6(39) = 41
X̂4 = 0.2(40) + 0.8(40) = 40 X̂4 = 0.4(40) + 0.6(41) = 40.6
X̂5 = 0.2(45) + 0.8(40) = 41 X̂5 = 0.4(45) + 0.6(40.6) = 42.36
X̂6 = 0.2(38) + 0.8(41) = 40.4 X̂6 = 0.4(38) + 0.6(42.36) = 40.616
X̂7 = 0.2(43) + 0.8(40.4) = 40.92 X̂7 = 0.4(43) + 0.6(40.616) = 41.5696
X̂8 = 0.2(39) + 0.8(40.92) = 40.54 X̂8 = 0.4(39) + 0.6(41.5696) = 40.5418
MSE (α = 0.2) = 11.58 and MSE(α = 0.4) = 12.78 so that α = 0.2 is the optimal.
41 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
Exponential Smoothing in R
42 of 189
Introduction to time series
Fundamental concepts
First and second order properties
Time Series Decomposition
Stationary and non-stationary models
Estimating the Seasonality
Autoregressive Models
Estimation the Trend
List of Some Useful R Functions and Homework
R> plot(out1,xlim=c(2,38))
R> pred <- predict(out1,n.ahead=6,prediction.interval=T)
R> lines(pred[,1],col="blue")
R> lines(pred[,2],col="green")
R> lines(pred[,3],col="green")
Holt−Winters filtering
35
30
25
Observed / Fitted
20
15
10
5
5 10 15 20 25 30 35
Time
Remarks
Xn n
X XX
Cov ( ai Xi ) = ai2 Var (Xi ) + 2 ai aj Cov (Xi , Xj )
i=1 i=1 i<j
Xn m
X n X
X m
Cov ( Xi , Yj ) = Cov (Xi , Yj )
i=1 j=1 i=1 j=1
46 of 189
Introduction to time series
First and second order properties
Autocovariance and Autocorrelation Functions
Stationary and non-stationary models
Sample Autocovariance and Autocorrelation
Autoregressive Models
List of Some Useful R Functions and Homework
1.0
200
0.8
0.6
150
ACF (cov)
0.4
ACF
100
0.2
50
0.0
−0.2
0
0 1 2 3 4 5 0 5 10 15
Lag Lag
47 of 189
Introduction to time series
First and second order properties
Autocovariance and Autocorrelation Functions
Stationary and non-stationary models
Sample Autocovariance and Autocorrelation
Autoregressive Models
List of Some Useful R Functions and Homework
or equivalently
n−h
1X
γ̂X (h) = (xt − x̄)(xt+h − x̄),
n
t=1
1 Pn
where x̄ = n t=1 xt .
The lag h sample autocorrelation is defined as
Pn−h
γ̂X (h) (xt − x̄)(xt+h − x̄)
−1 ≤ ρ̂X (h) = = t=1Pn 2
≤1
γ̂X (0) t=1 (xt − x̄)
48 of 189
Introduction to time series
First and second order properties
Autocovariance and Autocorrelation Functions
Stationary and non-stationary models
Sample Autocovariance and Autocorrelation
Autoregressive Models
List of Some Useful R Functions and Homework
49 of 189
Introduction to time series
First and second order properties
Autocovariance and Autocorrelation Functions
Stationary and non-stationary models
Sample Autocovariance and Autocorrelation
Autoregressive Models
List of Some Useful R Functions and Homework
50 of 189
Introduction to time series
First and second order properties
Autocovariance and Autocorrelation Functions
Stationary and non-stationary models
Sample Autocovariance and Autocorrelation
Autoregressive Models
List of Some Useful R Functions and Homework
0 1 2 3
5.230 -1.152 0.456 -0.961
R> Cor
Autocorrelations of series 'x', by lag
0 1 2 3
1.000 -0.220 0.087 -0.184
51 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Stationary Models
Definition
Stationary models: assume that the process remains in statistical
equilibrium with probabilistic properties that do not change over
time, in particular varying about a fixed constant mean level and
with constant variance.
52 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
53 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Definition
The joint distribution of Xt1 , Xt2 , . . . , Xtn is defined as:
FXt1 ,Xt2 ,...,Xtn (x1 , x2 , . . . , xn ) = P(Xt1 ≤ x1 , Xt2 ≤ x2 , . . . , Xtn ≤ xn ),
where x1 , x2 , . . . , xn are any real numbers.
Definition
A time series {Xt } is said to be Strong (or Strictly) Stationary if
for any time points t1 , t2 , . . . , tn ∈ Z, where n ≥ 1 and any scaler
shift (lag) h ∈ Z, the joint distribution of Xt1 , Xt2 , . . . , Xtn is the
same as the joint distribution of Xt1 +h , Xt2 +h , . . . , Xtn +h ; i.e.,
FXt1 ,Xt2 ,...,Xtn (x1 , x2 , . . . , xn ) = FXt1 +h ,Xt2 +h ,...,Xtn +h (x1 , x2 , . . . , xn )
54 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Definition
Time Invariant Process: A process has time invariant if it does not
depend on time.
Definition
A time series {Xt } is said to be Weak Stationary or Covariance
Stationary or Second-order Stationary if
The mean µt = E(Xt ) = µ is independent of t.
For all t&h, γX (h) = Cov (Xt , Xt+h ) = E[(Xt − µ)(Xt+h − µ)]
is time-invariant; i.e., the covariance function depends only on
the time separation h and not the actual time t.
55 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Remarks
56 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Remarks:
If t ∼ N(0, σ2 ), {t } is a Gaussian White Noise process.
Two random variables X and Y are uncorrelated when their
covariance coefficient is zero.
Two random variables X and Y are independent when their
joint probability distribution is the product of their marginal
probability distributions: ∀x, y ⇒ PX ,Y (x, y ) = PX (x)PY (y ).
If X and Y are independent, then they are also uncorrelated.
However, in general, the converse is not always true.
62 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(646)
R> white.noise <- rnorm(200)
R> ts.wn<- ts(white.noise)
R> par(mfrow=c(1,3))
R> plot(ts.wn,ylab="Gaussian Series",main="White Noise")
R> acf(ts.wn, main="Autocorrelation Function")
R> acf(ts.wn, type="partial", main="Partial ACF")
White Noise Autocorrelation Function Partial ACF
0.15
1.0
2
0.10
0.8
1
0.05
0.6
Gaussian Series
Partial ACF
0
ACF
0.00
0.4
−1
−0.05
0.2
−2
−0.10
0.0
−3
63 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Definition
The lead (forward) operator denotes by F(.) on an element of a
time series is used to shift the time index forward by one unit.
Definition
The difference operator denotes by ∆ expresses the difference
between two consecutive random variables (or their realizations).
64 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
BXt = Xt−1 ,
B2 Xt = B(BXt ) = BXt−1 = Xt−2 ,
More generally, Bh Xt = Xt−h , where h is any integer.
FXt = Xt+1 ,
F2 Xt = F(FXt ) = FXt+1 = Xt+2 ,
More generally, Fh Xt = Xt+h , where h is any integer.
∆Xt = Xt − Xt−1 = (1 − B)Xt ,
∆2 Xt = ∆(∆Xt ) = ∆Xt − ∆Xt−1 = (1 − B)∆Xt =
(1 − B)2 Xt = Xt − 2Xt−1 + Xt−2 ,
More generally, ∆d Xt = (1 − B)d Xt , where d is any integer.
Note that
Positive values of h define lags, while negative values define
leads: B−h Xt = Fh Xt = Xt+h ,
B0 Xt = F0 Xt = ∆0 Xt = Xt .
65 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Time
●
●
●
● ●
● ● ●
●
● ● ●
● ● ● ●
● ●
0.1
● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ● ● ● ●
● ● ● ●
● ● ● ● ●
● ● ● ● ● ● ● ●
−0.1
● ●
● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ● ● ●
● ● ● ● ● ● ●
●
● ● ● ●
● ●
−0.3
●
●
Time
●
●
●
● ● ●
● ● ● ● ● ● ● ●
0.1
● ● ● ● ● ●
●
● ● ●
●
●
● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ●
● ● ● ●
● ● ● ● ● ● ● ●
● ● ●
● ● ● ● ● ● ● ● ●
● ●
−0.1
● ● ● ● ● ● ● ●
● ● ● ● ●
● ● ● ● ●
● ● ● ● ●
● ● ●
●
● ● ●
● ● ● ● ●
−0.3
Time
67 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
0.2
−0.2
0 10 20 30 40
Lag
0.2
−0.2
0 10 20 30 40
Lag
first differences
1.0
0.6
ACF
0.2
−0.2
0 10 20 30 40
Lag
68 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Linear Processes
69 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Definition
A time series {Xt }, with zero mean, satisfies
70 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(12345)
R> ar1.sim<-arima.sim(n=100,list(order=c(1,0,0),ar=0.8))
R> par(mfrow=c(1,3))
R> plot(ar1.sim, ylab="X(t)", main="A simulated AR(1)")
R> acf(ar1.sim, main="Autocorrelation Function")
R> acf(ar1.sim, type="partial", main="Partial ACF")
A simulated AR(1) Autocorrelation Function Partial ACF
1.0
0.8
0.6
4
0.6
0.4
Partial ACF
0.4
2
ACF
X(t)
0.2
0.2
0
0.0
0.0
−0.2
−2
−0.2
0 20 40 60 80 100 0 5 10 15 20 5 10 15 20
72 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(12345)
R> ar11.sim<-arima.sim(n=100,list(order=c(1,0,0),ar=-0.8))
R> par(mfrow=c(1,3))
R> plot(ar11.sim, ylab="X(t)", main="A simulated AR(1)")
R> acf(ar11.sim, main="Autocorrelation Function")
R> acf(ar11.sim, type="partial", main="Partial ACF")
A simulated AR(1) Autocorrelation Function Partial ACF
0.2
1.0
2
0.0
0.5
−0.2
0
Partial ACF
ACF
X(t)
0.0
−0.4
−2
−0.5
−0.6
−4
0 20 40 60 80 100 0 5 10 15 20 5 10 15 20
73 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(1965)
R> ar2<-arima.sim(n=200,list(order=c(2,0,0),ar=c(1.1,-0.3))
R> par(mfrow=c(1,3))
R> plot(ar2, ylab="X(t)", main="A simulated AR(2)")
R> acf(ar2, main="Autocorrelation Function")
R> acf(ar2, type="partial", main="Partial ACF")
A simulated AR(2) Autocorrelation Function Partial ACF
0.8
1.0
4
0.6
0.8
2
0.4
0.6
Partial ACF
0
ACF
X(t)
0.4
0.2
−2
0.2
0.0
−0.2
0.0
−4
R> set.seed(6436)
R> ma1.sim<-arima.sim(n=200,list(order=c(0,0,1),ma=0.8))
R> par(mfrow=c(1,3))
R> plot(ma1.sim, ylab="X(t)", main="A simulated MA(1)")
R> acf(ma1.sim, main="Autocorrelation Function")
R> acf(ma1.sim, type="partial", main="Partial ACF")
A simulated MA(1) Autocorrelation Function Partial ACF
1.0
4
0.4
0.8
3
2
0.6
0.2
Partial ACF
1
ACF
X(t)
0.4
0
0.0
0.2
−1
−0.2
0.0
−2
−0.2
−3
76 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(6436)
R> ma11.sim<-arima.sim(n=200,list(order=c(0,0,1),ma=-0.8))
R> par(mfrow=c(1,3))
R> plot(ma11.sim, ylab="X(t)", main="A simulated MA(1)")
R> acf(ma11.sim, main="Autocorrelation Function")
R> acf(ma11.sim, type="partial", main="Partial ACF")
A simulated MA(1) Autocorrelation Function Partial ACF
1.0
0.1
2
0.0
0.5
−0.1
Partial ACF
0
ACF
X(t)
−0.2
0.0
−0.3
−2
−0.4
−4
−0.5
77 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(14762)
R> ma2<-arima.sim(n=200,list(order=c(0,0,2),ma=c(0.8,0.6)))
R> par(mfrow=c(1,3))
R> plot(ma2, ylab="X(t)", main="A simulated MA(2)")
R> acf(ma2, main="Autocorrelation Function")
R> acf(ma2, type="partial", main="Partial ACF")
A simulated MA(2) Autocorrelation Function Partial ACF
1.0
4
0.6
0.8
2
0.4
0.6
Partial ACF
ACF
X(t)
0.4
0.2
0.2
−2
0.0
0.0
−0.2
−4
Definition
A time series {Xt }, with zero mean, is called
Autoregressive-Moving Average of order (p, q) and denoted by
ARMA (p, q) if it can be written as
p
X q
X
Xt = φi Xt−i + θj t−j ,
|i=1 {z } j=0
| {z }
Autoregressive Part Moving Average Part
79 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
81 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(6436);par(mfrow=c(1,3))
R> arma1.sim<-arima.sim(n=200,list(order=c(1,0,1),
+ ar=0.8,ma=-0.6))
R> plot(arma1.sim,ylab="X(t)",main="A simulated ARMA(1,1)")
R> acf(arma1.sim, main="Autocorrelation Function")
R> acf(arma1.sim, type="partial", main="Partial ACF")
A simulated ARMA(1,1) Autocorrelation Function Partial ACF
0.3
1.0
3
0.8
0.2
2
0.6
1
Partial ACF
0.1
ACF
X(t)
0.4
0
0.0
−1
0.2
−2
0.0
−0.1
−3
R> set.seed(6436);par(mfrow=c(1,3))
R> arma21.sim<-arima.sim(n=200,list(order=c(2,0,1),
+ ar=c(0.8,-0.4),ma=-0.6))
R> plot(arma21.sim,ylab="X(t)",main="A simulated ARMA(2,1)"
R> acf(arma21.sim, main="Autocorrelation Function")
R> acf(arma21.sim, type="partial", main="Partial ACF")
A simulated ARMA(2,1) Autocorrelation Function Partial ACF
4
1.0
0.3
3
0.8
0.2
2
0.6
0.1
1
Partial ACF
0.4
ACF
X(t)
0.0
0
0.2
−1
−0.1
0.0
−2
−0.2
−0.2
−3
R> set.seed(6436);par(mfrow=c(1,3))
R> arma12.sim<-arima.sim(n=200,list(order=c(1,0,2),
+ ar=0.8,ma=c(-0.6,0.4)))
R> plot(arma12.sim,ylab="X(t)",main="A simulated ARMA(1,2)"
R> acf(arma12.sim, main="Autocorrelation Function")
R> acf(arma12.sim, type="partial", main="Partial ACF")
A simulated ARMA(1,2) Autocorrelation Function Partial ACF
4
1.0
0.5
0.8
0.4
2
0.3
0.6
Partial ACF
0.2
ACF
X(t)
0.4
0
0.1
0.2
0.0
−2
0.0
−0.1
−0.2
Xt = φXt−1 + t or (1 − φB)Xt = t
Xt = t + θt−1 or Xt = (1 + θB)t
Definition
A time series {Xt }, with zero mean, is called
Autoregressive-Integrated-Moving Average of order (p, d, q),
denoted by ARIMA (p, d, q) if the dth differences of the {Xt }
series is an ARMA (p, q) process.
The process in the backshift operator may be written as:
88 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Remarks
ARIMA models are applied in some cases where data show
evidence of non stationarity, where an initial differencing step
can be applied one or more times to eliminate the non
stationarity.
AR (p) ≡ARIMA (p, 0, 0),
MA (q) ≡ARIMA (0, 0, q),
ARI (p, d) ≡ARIMA (p, d, 0),
IMA (d, q) ≡ARIMA (0, d, q),
ARMA (p, q) ≡ARIMA (p, 0, q),
WN ≡ARIMA (0,0,0),
I (d) ≡ARIMA (0, d, 0). Note that I (1) is the well-known
random walk, Xt = Xt−1 + t , that is widely used to describe
the behavior of the series of a stock price (as we will discuss
later).
89 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
R> set.seed(6436);par(mfrow=c(1,3))
R> arima.sim<-arima.sim(n=200,list(order=c(2,1,1),
+ ar=c(0.8,-0.4),ma=-0.6))
R> plot(arima.sim,ylab="X(t)",main="A simulated ARIMA(2,1,1
R> acf(arima.sim, main="Autocorrelation Function")
R> acf(arima.sim, type="partial", main="Partial ACF")
A simulated ARIMA(2,1,1) Autocorrelation Function Partial ACF
1.0
1.0
0.8
20
0.8
0.6
0.6
15
Partial ACF
ACF
X(t)
0.4
0.4
10
0.2
0.2
5
0.0
0.0
0
92 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
ΘQ (Bs ) = 1 + Q is s
P
i=1 Θi B polynomial in B of degree Q,
with no common roots between ΦP (Bs ) and ΘQ (Bs ), p, d, and q
are the order of non-seasonal AR model, MA model and ordinary
differencing respectively, whereas P, D, and Q are the order of
Seasonal Autoregressive (SAR ) model, Seasonal Moving Average
(SMA ) model, and seasonal differencing respectively. 93 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Remarks
94 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
(1 − B)(1 − B5 )Xt = t
1.0
600
0.8
500
Passengers (1000's)
0.6
400
ACF
0.4
300
0.2
200
0.0
100
−0.2
1950 1952 1954 1956 1958 1960 0.0 0.5 1.0 1.5
Time Lag
R> par(mfrow=c(1,2))
R> AP.decom <- decompose(AirPassengers, "multiplicative")
R> plot(ts(AP.decom$random[7:138]))
R> acf(AP.decom$random[7:138]); par(mfrow=c(1,1))
Series AP.decom$random[7:138]
1.10
1.0
0.8
ts(AP.decom$random[7:138])
1.05
0.6
1.00
0.4
ACF
0.2
0.95
−0.2 0.0
0.90
0 20 40 60 80 100 120 0 5 10 15 20
Time Lag
98 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
1.0
2
1
0.6
Series 1
ACF
0.2
−2
−0.2
−4
0 20 40 60 80 100 0 10 20 30 40
Time Lag
= θσ 2 , h = ±1,
0, h = ±2, ±3, . . .
1, h=0
γX (h) θ
ρX (h) = = 2
, h = ±1
γX (0) 1+θ
0, h = ±2, ±3, . . .
100 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
101 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
1.0
0.8
0.5
0.6
ACF
ACF
0.4
0.0
0.2
0.0
−0.5
−0.2
0 5 10 15 20 0 5 10 15 20
Lag Lag
MA(2), theta1 = 0.7 and theta2 = 0.3 MA(2), theta1 = −0.7 and theta2 = 0.3
1.0
1.0
0.8
0.5
0.6
ACF
ACF
0.4
0.0
0.2
0.0
−0.5
0 5 10 15 20 0 5 10 15 20
Lag Lag
102 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
104 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
⇒ Π∞ (B)Xt = t ,
1− ∞
P∞
where Π∞ (B) = Θq (B)−1 i i
P
P= i=1 πi B = − i=0 πi B with
∞
π0 = −1, and πi satisfy i=0 |πi | < ∞.
Note that the condition of finite sum ( ∞
P
i=0 |πi | < ∞) ensures
that the AR (∞) series is convergent (i.e., MA (q) is invertible).
105 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
1
t = Xt = Π∞ (B)Xt ,
1 + θB
∞
X ∞
X
i i
(−θ) B = −πi Bi .
i=0 i=0
πi = (−1)i+1 (θ)i ∀i ≥ 0.
109 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
Xt = t − 0.1t−1 + 0.42t−2 .
Xt = t − t−1 + 0.5t−2 .
112 of 189
Introduction to time series
First and second order properties Weak and Strong (Strictly) Stationarity
Stationary and non-stationary models White Noise Process
Autoregressive Models ARIMA and SARIMA Models
List of Some Useful R Functions and Homework
116 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
∞
X
The AR (1) process in MA (∞) representation: Xt = φi t−i
i=0
∞
X
The mean of Xt : E(Xt ) = φi E(t−i ) = 0 (independent of t).
i=0
∞ ∞
X X σ2
The variance: γX (0) = E( φ2i 2t−i ) = σ 2 φ2i = .
1 − φ2
i=0 i=0
The autocovariance is independent of t as follows:
∞ X
X ∞
γX (h) = E(Xt Xt+h ) = φi φj E(t−i t+h−j )
i=0 j=h
∞ ∞
X X φh
= σ2 φi φi+h = φh σ 2 φ2i = σ 2
1 − φ2
i=0 i=0
γX (h)
The autocorrelation: ρX (h) = = φh (independent of t).
γX (0)
117 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
R> set.seed(125)
R> ar.1<-arima.sim(n=200,list(order=c(1,0,0),ar=0.8))
R> ar.2<-arima.sim(n=200,list(order=c(1,0,0),ar=-0.5))
R> par(mfrow=c(1,2))
R> acf(ar.1,main="Phi = 0.8"); acf(ar.2,main="Phi = -0.5")
R> par(mfrow=c(1,1))
Phi = 0.8 Phi = −0.5
1.0
1.0
0.8
0.8
0.6
0.6
0.4
ACF
ACF
0.4
0.2
0.0
0.2
−0.2
0.0
−0.4
0 5 10 15 20 0 5 10 15 20
Lag Lag
118 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Xt = 0.6Xt−1 + t , t ∼ WN(0, 4)
are
ρX (h) = φh = 0.6h ∀h ≥ 0,
Thus ρX (0) = 1, ρX (1) = 0.6, ρX (2) = 0.62 = 0.36, . . ..
R> Lag <- 0:8
R> rho <- 0.6^Lag
R> round(rho,3)
[1] 1.000 0.600 0.360 0.216 0.130 0.078 0.047 0.028 0.017
119 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
120 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Definition
The condition for the Autoregressive process of order 1, AR (1):
Xt = φXt−1 + t , to be stationary is that the absolute value of the
root of (1 − φB) = 0 must lie outside the unit circle. That is, the
AR (1) is stationary if |B| = | φ1 | > 1, or equivalently, if |φ| < 1,
122 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
|φ2 | < 1
φ1 + φ2 < 1
φ2 − φ1 < 1
Examples
Xt = 1.1Xt−1 − 0.4Xt−2 + t is stationary.
Xt = 0.6Xt−1 − 1.3Xt−2 + t is not stationary (|φ2 | ≮ 1).
Xt = 0.6Xt−1 + 0.8Xt−2 + t is not stationary (φ1 + φ2 ≮ 1).
Xt = −0.4Xt−1 + 0.7Xt−2 + t is not stationary (φ2 − φ1 ≮ 1).
123 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
125 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
126 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Xt = 0.1Xt−1 − 0.42Xt−2 + t
The ψj satisfy
130 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Recall that Xt = ∞
P
j=0 ψj t−j , where the coefficients ψj can be
1 + θB
calculated from the relation Ψ∞ (B) = Φp (B)−1 Θq (B) =
1 − φB
(see impulse response sequence of ARMA (p, q) models), where
ψ0 = 1 and ψ1 = φ + θ for the ARMA (1,1) case.
132 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
∞
X ∞
X
E(t+h Xt ) = E(t+h ψj t−j ) = ψj E(t+h t−j )
j=0 j=0
σ2,
ψ0 for h = 0;
= (2)
0, for h ≥ 1.
∞
X ∞
X
E(t+h−1 Xt ) = E(t+h−1 ψj t−j ) = ψj E(t+h−1 t−j )
j=0 j=0
ψ1 σ 2 , for h = 0;
= ψ0 σ 2 , for h = 1; (3)
0, for h ≥ 2.
Furthermore, ψ0 = 1 and ψ1 = φ + θ.
133 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
= φγ(0) + σ 2 θ, for h = 1;
φγ(h − 1), for h ≥ 2.
R> set.seed(13675)
R> sim<-arima.sim(n=200,list(order=c(1,0,1),ar=0.9,ma=0.5))
R> par(mfrow=c(1,2))
R> plot(sim,ylab=""); acf(sim,lag.max=85)
R> par(mfrow=c(1,1))
Series sim
1.0
5
0.8
0
0.6
ACF
0.4
−5
0.2
0.0
−10
−0.2
Time Lag
141 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Cramer’s Rule
Definition
Consider the system of n linear equations for n unknowns,
represented in matrix multiplication form: AX = b, where the
n × n matrix A has a nonzero determinant, and the vector
X = (x1 , x2 , . . . , xn )T is the column vector of the unknowns
variables. Then the system has a unique solution, whose individual
values for the unknowns are given by
det(Ai )
xi = , i = 1, 2, . . . , n,
det(A)
142 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
1 ρ1 ρ2 . . . ρh−2 ρ1
ρ1 1 ρ 1 . . . ρh−3 ρ2
.. ..
. ... ... ... ... .
ρh−1 ρh−2 ρh−3 . . . ρ 1 ρh
φh,h =
1 ρ1 ρ2 . . . ρh−2 ρh−1
ρ1 1 ρ1 . . . ρh−3 ρh−2
.. ..
. ... ... ... ... .
ρh−1 ρh−2 ρh−3 ... ρ1 1
148 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
φ1,1 = ρ1 = 0.7
1 ρ1 1 0.7
ρ1 ρ2 0.7 0.5
φ2,2 = = = 0.0196
1 ρ1 1 0.7
ρ1 1 0.7 1
1 ρ1 ρ1 1 0.7 0.7
ρ1 1 ρ2 0.7 1 0.5
ρ2 ρ1 ρ3 0.5 0.7 0.2
φ3,3 = = = −0.392
1 ρ1 ρ2 1 0.7 0.5
ρ1 1 ρ1 0.7 1 0.7
ρ2 ρ1 1 0.5 0.7 1
149 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Remarks
150 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
0.0
0.4
−0.2
Partial ACF
Partial ACF
0.2
−0.4
0.0
−0.6
5 10 15 20 5 10 15 20
Lag Lag
AR(2), phi1 = 0.4 and phi2 = 0.5 AR(2), phi1 = 1.1 and phi2 = −0.4
0.6
0.6
0.4
0.4
Partial ACF
Partial ACF
0.2
0.2
0.0
0.0
−0.2
−0.2
5 10 15 20 5 10 15 20
Lag Lag
151 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
0.6
1.0
0.8
0.4
0.6
Partial ACF
0.2
0.4
ACF
0.2
0.0
0.0
−0.2
−0.2
0 5 10 15 5 10 15
Lag Lag
157 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Definition
The process Xt = Xt−1 + t , where t is a White Noise WN(0, σ 2 )
for all t ≥ 1, (i.e., an AR (1) process with φ = 1) is called a
random walk (unit-root) processes.
In words, the value of X in period t is equal to its value in t − 1,
plus a random step due to the white-noise shock t .
158 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
X1 = x0 + 1 = a + 1
X2 = x1 + 2 = a + 1 + 2
X3 = x2 + 3 = a + 1 + 2 + 3
.. .
. = ..
Xt
Xt = xt−1 + t = a + i
i=1
160 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
161 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
∆Xt = δXt−1 + t .
∆Xt = a0 + δXt−1 + t .
3 Test for a unit root with drift and deterministic time trend
∆Xt = a0 + a1 t + δXt−1 + t .
162 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
164 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
165 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
166 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
R> set.seed(348)
R> n<-100; epsilon<-rnorm(n); x<-epsilon[1]
R> for (i in 1:(n-1)){x[i+1] <- x[i]+epsilon[i+1]}
R> par(mfrow=c(1,4)) ## Try x <- cumsum(epsilon)
R> plot(ts(x),ylab="X(t)",main="Random walk series")
R> acf(ts(x), main="Autocorrelation function")
R> ts.plot(diff(x),main="First difference")
R> acf(ts(diff(x)),main="Autocorrelation-first difference")
Random walk series Autocorrelation function First difference Autocorrelation−first difference
1.0
1.0
2
10
0.8
0.8
1
0.6
0.6
5
diff(x)
ACF
ACF
X(t)
0.4
0.4
0.2
0.2
−1
0
0.0
0.0
−2
−0.2
−0.2
0 20 40 60 80 100 0 5 10 15 20 0 20 40 60 80 100 0 5 10 15
167 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Example
Consider the AR (1) model X̂t = 0.946Xt−1 , where n = 34.
The Dickey-Fuller test statistic is
168 of 189
Introduction to time series
Second Order Properties of AR Models
First and second order properties
Stationarity of AR Models
Stationary and non-stationary models
Partial Autocorrelation Function (PACF )
Autoregressive Models
Random Walk Process
List of Some Useful R Functions and Homework
Test for a unit root with drift and deterministic time trend
R> set.seed(348);n<-100;epsilon<-rnorm(n);x<-epsilon[1]
R> x <-cumsum(epsilon);plot(ts(x),ylab="X(t)")
R> library("tseries");adf.test(x)
Augmented Dickey-Fuller Test
data: x
Dickey-Fuller = -1.849, Lag order = 4, p-value = 0.6392
alternative hypothesis: stationary
10
5
X(t)
R-Function Description
read.table() reads data into a data frame.
scan() read data into a vector or list.
attach() makes names of column variables available.
ts() produces a time series object.
ts.plot() produces a time plot for one or more series.
points() add a sequence of points centered to a specified coordinates.
window() extracts a subset of a time series.
aggregate() creates an aggregated series.
time() extracts the time from a time series object.
decompose() decomposes a series into the components trend, seasonal effect, and residual.
summary() summarises an R object.
mean() returns the mean (average).
var() returns the variance with denominator n − 1.
sd() returns the standard deviation.
polyroot() find zeros of a real or complex polynomial.
Mod() check whether the roots of the polynomial have modulus > 1 or not.
adf.test() Computes the Augmented Dickey-Fuller test for the null that x has a unit root. (tseries package).
nsdiffs() Number of differences required for a stationary series. If test="adf", the Augmented Dickey-Fuller
test is used. (forecast package).
ur.df() Performs the augmented Dickey-Fuller unit root test. (urca package).
adfTest() Augmented Dickey-Fuller test for unit roots.(fUnitRoots package).
urdfTest() Augmented Dickey-Fuller test for unit roots.(fUnitRoots package).
170 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
R-Function Description
str() compactly display the structure of an arbitrary R object.
cov() returns the covariance with denominator n − 1.
cor() returns the correlation.
acf() returns the correlogram (or sets the argument to obtain autocovariance function).
pacf() returns the partial autocorrelation function.
lm() linear models (least squares fit).
predict() forecasts future values.
forecast() forecasting time series (forecast package).
HoltWinters() estimates the parameters of the Holt-Winters or exponential smoothing model.
coef() extracts the coefficients of a fitted model.
resid() extracts the residuals from a fitted model.
diff() returns suitably lagged and iterated differences.
round() round the values in its first argument to the specified number of decimal places.
set.seed() provide a seed for simulations ensuring that the simulations can be reproduced.
par(mfrow=c(i, j)) set a graphical device to insert i × j pictures on one plot.
ar() fit an autoregressive time series model to the data, by default selecting the complexity by AIC .
arima() fit an ARIMA model to a univariate time series.
auto.arima() returns best ARIMA model according to either AIC , AICc or BIC value (forecast package).
arima.sim() simulate from an ARIMA model.
varima.sim() Simulate data from seasonal/nonseasonal ARIMA models (portes package).
171 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
R-Function Description
AIC() Akaike information criterion for selection model.
BIC() Bayesian information criterion for selection model.
Box.test() compute the Box-Pierce or Ljung-Box portmanteau tests.
BoxPierce() compute the univariate or multivariate Box-Pierce portmanteau test (portes package).
LjungBox() compute the univariate or multivariate Ljung-Box portmanteau test (portes package).
MahdiMcLeod() compute the univariate Peňa-Rodrı́guez or multivariate Mahdi-McLeod portmanteau test (portes).
tsdiag() diagnostic plots for time series fits.
qqplot() produces a Q-Q plot of two datasets.
qqnorm() produces a normal Q-Q plot of points.
qqline() draw the diagonal line for normal Q-Q plots produced by qqnorm().
shapiro.test() Performs the Shapiro-Wilk test of normality.
layout() divides the device up into as many rows and columns as there are in matrix mat,
with the column-widths and the row-heights specified in the respective arguments.
boxplot() produce box-and-whisker plot(s) of the given (grouped) values.
start() extract and encode the times the first observation were taken.
end() extract and encode the times the last observation were taken.
frequency() returns the number of samples per unit time.
polyroot() finds zeros of polynomials and roots of the characteristic equation to check for stationarity.
det() calculate the Determinant of a Matrix.
matrix() create a matrix from a given set of values.
172 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
173 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
For the macroeconomic Longley’s Economic Regression Data with
the name longley available from the R package datasets:
1 Import the data into R.
(X −axis).
6 Fit the linear regression using R with the lm() function,
174 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
175 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
The data with the name w6 available from the link
http://astro.temple.edu/~wwei/data.html represents the
realization yearly US Tobacco production from the 1871 to 1984
(in millions of pounds).
1 Import the data into R using scan() R function.
Homework
For the data with the name w1 available from the link
http://astro.temple.edu/~wwei/data.html.
1 Use the exponential smoothing method with four different
smoothing parameters α = 0.2, 0.4, 0.5 and 0.8 to forecast the
1-day ahead.
2 What is the optimal value of the smoothing parameter α?.
3 Use the R function HoltWinters() to find the exponential
smoothing model for the above values of α.
4 Plot the original series together with the smoothing series.
177 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
Compute and plot the values of γ̂X (h), ρ̂X (h), and φ̂h,h for lag
h = 0, 1, 2, 3 and 4. Check your results using R.
t Xt t Xt
1 2 11 1
2 1 12 1
3 4 13 4
4 3 14 3
5 3 15 5
6 5 16 6
7 2 17 4
8 1 18 2
9 0 19 5
10 3 20 3
178 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
179 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
180 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
181 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
1 Classify the following ARMA models (that is, state if they are
ARMA (1,1), or ARMA (1,2), etc.), determine the mean of
each model, rewrite each one using the backshift operator,
and finally convert each model into a pure AR model, and into
a pure MA model.
Yt − 0.17Yt−1 + 0.19Yt−2 = 12 + t + 0.2t−1
Zn+1 = 0.5Zn − 0.2Zn−1 + n+1 − 0.6n − 0.18n−1 + 0.1n−2
At + 0.2At−1 + 0.04At−2 = t + 0.4t−1 + 0.3t−2 − 0.2t−3
2 Find the autocovariance and autocorrelation functions of the
time series models:
Homework
183 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
184 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
185 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
186 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
187 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
Use the build in R function arima.sim() to simulate the following
i.i.d.
models (assume that n = 300 and t ∼ N(0, 1)). Plot each one
and compute the autocovariance, autocorrelation, and partial
autocorrelation functions using the acf() and pacf() R functions.
Xt = 0.4Xt−1 + t
Xt = −0.7Xt−1 + t
Xt = t + 0.2t−1
Xt = 0.1Xt−1 + 0.3Xt−2 + t
Xt = t − 0.6t−1 + 0.3t−2
Xt = 0.2Xt−1 + t + 0.8t−1
Xt = 0.7Xt−1 + 0.2Xt−2 + t + 0.5t−1
Xt = 0.9Xt−1 − 0.4Xt−2 + t + 1.2t−1 − 0.3t−2
188 of 189
Introduction to time series
First and second order properties
List of Some Useful R Functions
Stationary and non-stationary models
Homework
Autoregressive Models
List of Some Useful R Functions and Homework
Homework
Write a short piece of R-code (use set.seed(345)) to simulate
the AR (1) model Xt = φXt + t of length 500, where
t ∼ N(2, 8), for each
φ : φ = 0.9, −0.9, 0.6, −0.6, 0.3, −0.3, 1.5, −1.5, 0.1, −0.1.
Plot each simulated series and plot each ACF and PACF .
Comment on your findings: What effect does the value of φ
have on the stationarity of the series?
Write a short piece of R-code (use set.seed(345)) to simulate
the MA (1) model Xt = t + θt−1 of length 500, where
t ∼ N(0, 1), for each
θ : θ = 0.9, −0.9, 0.6, −0.6, 0.3, −0.3, 1.5, −1.5, 0.1, −0.1.
Plot each simulated series and plot each ACF and PACF .
Comment on your findings: What effect does the value of θ
have on the stationarity of the series?
189 of 189