Module 1 Introduction to Time Series Iowa State University

advertisement
Module 1
Introduction to Time Series
Class notes for Statistics 451: Applied Time Series
Iowa State University
Copyright 2015 W. Q. Meeker.
November 11, 2015
17h 19min
1-1
Module 1
Segment 1
Time Series Examples
1-2
Time Series Data
A sequence of observations taken over time (usually equally
spaced) y1, y2, . . . , yt, . . . yn where n is the number of observations in the “realization”
• Univariate – single series, e.g., daily closing price of IBM
common stock.
• Multivariate – two or more series (vector time series)
(e.g. daily closing price of common stock of Apple, IBM,
Microsoft gives 3 values per day).
• Time interval: yearly, monthly, quarterly, weekly, daily, hourly,
every minute, . . . every k nanoseconds . . .. +
• Population of units → Sample
• Process operating in time → Realization
1-3
Continuous Time and Discrete Time
• Time is continuous, but data are usually reported at discrete
points in time.
• Thus “sampling” a continuous time series leads to a discrete
time series.
• Sampling is usually equally spaced in time (sampling sometimes known as “reporting”)
• Time series data are usually not independent, especially if
sampling interval is small. Observations close together are
often more alike than those far apart (e.g. daily temperatures).
1-4
plot(ship.ts)
50000
60000
ship.ts
70000
80000
90000
Manufacturer’s Shipments 1967-1975
1968
1970
1972
1974
Time
1-5
90000
Smoothed Manufacturer’s Shipments 1967-1975
plot(ship.ts)
50000
60000
ship.ts
70000
80000
lines(smooth(ship.ts), col=2, lwd=3)
1968
1970
1972
1974
Time
1-6
Seasonal Data Example
US Housing Starts 1966-1974
150
100
50
Thousands of Homes
200
US Housing Starts 1966−1974
1966
1968
1970
1972
1974
Year
1-7
Types of Time Series Responses
• Continuous (e.g. temperature, concentration).
• Discrete (e.g., number of people, number manufactured)
(often from aggregation). We often approximate discrete
responses with a continuous model.
• Binary (e.g., success or failure).
1-8
Time Series Applications
• Economics (e.g., GNP, NNP, Unemployment Rate, Interest
Rates, Money supply)
• Business (e.g., Inventory, Cash, Sales, Prices, Quality Indices, Stock Price)
• Sociology (e.g., Crime Rates, Divorce Rates)
• Meteorology (e.g., Rainfall, Temperature, Wind Speed)
• Astronomy (e.g., Solar Activity, Sun Spots, Star Brightness)
• Ecology (e.g., Air Pollution, Water Pollution, Wildlife Population)
• Engineering
1-9
International Airline Passengers 1949-1960
400
300
200
100
Thousands of Passengers
500
600
International Airline Passengers
1950
1952
1954
1956
1958
1960
Year
1 - 10
International Airline Passengers 1949-1960
400
300
200
100
Thousands of Passengers
500
600
International Airline Passengers
1950
1952
1954
1956
1958
1960
Year
1 - 11
Log International Airline Passengers 1949-1960
5.5
5.0
log(Thousands of Passengers)
6.0
6.5
Log International Airline Passengers
1950
1952
1954
1956
1958
1960
Year
1 - 12
International Airline Passengers 1949-1960
300
200
100
Thousands of Passengers
400
500
600
International Airline Passengers
1950
1952
1954
1956
1958
1960
Year
1 - 13
Reasons for Analyzing Time Series
• Description of features (level, trend, cycles, seasonality,
variability)
◮ Graphical (time series plots)
◮ Numerical (mean, standard deviation, autocorrelation)
• Explanation
Explanatory Variables
• Prediction (Forecasting)
Next Year’s Sales
• Control
Quality of Manufacturing Process Economy
1 - 14
Module 1
Segment 2
Time Series Filters
1 - 15
Filters
• Filters are like functions, but for time series.
x1, x2, . . . and y = y1, y2, . . . . Then y = f (x):
xt
f
Let x =
yt
• Linear filter:
yt =
+s
X
ar xt+r = a−q xt−q +a−q+1xt−q+1+. . . a0xt+. . . asxt+s.
r=−q
For example with q = 2, s = 2, and ar = 1/5,
yt =
2
X
ar xt+r = (xt−2 + xt−1 + xt + xt+1 + xt+2)/5
r=−2
which is a “moving average” filter.
1 - 16
Filters in Series
Two (or more) filters in series form an overall filter:
xt
yt
f1
f2
zt
f3
f1
f3 = f2 ⊙ f1
x1
(x1 + x2)/2
(x1 + 2x2 + x3 )/4
x2
(x2 + x3)/2
(x2 + 2x3 + x4 )/4
x3
(x3 + x4)/2
x4
...
...
...
zt =
1
X
ar xt+r
r=−1
where a−1 = 1/4, a0 = 1/2, and a1 = 1/4. This particular
weighted moving average is also known as a “Hanning filter.”
1 - 17
400
300
200
100
Thousands of Passengers
500
Smoothed International Airline Passengers 1949-1960
12-point moving average
1949
1951
1953
1955
1957
1959
1961
Year
1 - 18
400
300
200
Thousands of Passengers
500
Smoothed International Airline Passengers 1949-1960
(4253H,twice)
1950
1952
1954
1956
1958
1960
Year
1 - 19
Difference Noise
International Airline Passengers 1949-1960
tsplot(passengers.ts-smooth.spline(passengers.ts))
40
20
0
-20
Thousands of Passengers
60
Passenger-smooth(Passenger)
Jan, 50
Jan, 52
Jan, 55
Jan, 57
Jan, 60
Year
1 - 20
Ratio Noise
International Airline Passengers 1949-1960
tsplot(passengers.ts/smooth.spline(passengers.ts))
1.00
0.95
0.90
0.85
ratio
1.05
1.10
1.15
Passenger/smooth(Passenger)
Jan, 50
Jan, 52
Jan, 55
Jan, 57
Jan, 60
Year
1 - 21
Module 1
Segment 3
Classical Time Series Decomposition
1 - 22
The “Classical” Decomposition Model
Multiplicative Model:
Zt = Tt × Ct × St × It
• Decompose Zt into Tt, Ct, St and It, t = 1, . . . , n (trend, cycle,
seasonal, and irregular).
• There are many possible algorithms for doing the decomposition.
• Operationally it may not be desirable to separate Tt and Ct .
• An additive model could also be used (especially after a
transformation)
Zt = Tt + Ct + St + It
1 - 23
4.0
4.2
3.8
−0.10
0.00
remainder
0.05
0.10
3.4
trend
4.6
−0.2
−0.1
0.0
seasonal
0.1
0.2
3.5
data
4.5
5.0
Seasonal Decomposition of Time Series by Loess
International Airline Passengers 1949-1960
Periodic Seasonality
plot(stl(Passengers.ts^ (0.25),s.window="periodic"))
1950
1952
1954
1956
1958
1960
time
1 - 24
4.0
4.2
3.8
−0.06
−0.02
remainder
0.02
0.06
3.4
trend
4.6
−0.2
0.0
0.1
seasonal
0.2
0.3
3.5
data
4.5
5.0
Seasonal Decomposition of Time Series by Loess
International Airline Passengers 1949-1960
Evolving Seasonality
plot(stl(Passengers.ts^ (0.25),s.window=7))
1950
1952
1954
1956
1958
1960
time
1 - 25
Applications of the “Classical” Decomposition Model
Model:
Zt = Tt × Ct × St × It
• Forecast components into future and combine to forecast
Zt. Suppose there are n = 100 observations in a realization.
◮ Forecast T101, C101, S101, I101.
◮ Ẑ101 = T̂101 × Ĉ101 × Ŝ101 × Iˆ101
• Smoothed series:
Smootht = Tt × St × Ct
(no It)
• Seasonally adjusted series (also known as deseasonalized):
Dt = Tt × Ct × It (no St)
1 - 26
For more information on decomposition methods, see
• Some elementary business statistics textbooks
• Census Bureau program X-12 ARIMA (www.census.gov)
• Census Bureau program X-13 ARIMA SEATS (Signal Extraction ARIMA Time Series Models)
• SAS ETS PROC X-12
• S-Plus function sabl() (Seasonal Analysis Bell Labs)
• R function stl() (Seasonal Decomposition by Loess)
1 - 27
Module 1
Segment 4
Shaded Time Series Plots
1 - 28
US Housing Starts 1966-1974
plot(hstart.ts)
150
100
50
Thousands of Homes
200
US Housing Starts 1966−1974
1966
1968
1970
1972
1974
Year
1 - 29
US Housing Starts 1966-1974
shaded.tsplot(hstart.ts,top=F)
150
100
US Housing Starts
50
Thousands of Homes
200
shaded.tsplot(hstart.ts)
1966
1968
1970
1972
1974
Year
1 - 30
US Housing Starts 1966-1974
shaded.tsplot(hstart.ts,top=T)
150
100
US Housing Starts
50
Thousands of Homes
200
shaded.tsplot(hstart.ts,top=T)
1966
1968
1970
1972
1974
Year
1 - 31
Balance of Trade Between England and NA 1700-1780
William Playfair, Commercial and Political Atlas, 1786
1 - 32
0.5
income
1.0
1.5
Balance of Trade in England 1700-1780
William Playfair, Commercial and Political Atlas, 1786
0
20
40
60
80
Index
1 - 33
Playfair Recreated
http://dougmccune.com/flex/recreatingPlayfair/
1 - 34
Module 1
Segment 5
Introduction to Autocorrelation
1 - 35
50
55
60
Percent CO2 Outlet Gas
(sampling interval 9 seconds)
plot(gasry.tsd)
0
50
100
150
200
250
300
1 - 36
•••
••
• •• •
• •••• • • • •
• •
••••••• • •••••• ••
•
•
• • ••• •••
•• •••••• •••• •••• • •• •
• • •••••• •• •• •••• •
• •••••••• •••• • ••• •
•••••••••••••••••••••• • •••••• •• •
• ••••••••• •• ••••••••••••• •
••••• • •••
• ••••••••••••••••••••• •••
• • • •••• •••• ••••••• ••• •
• •••• ••• ••••
• ••••• • ••
• •
• •• •• •
• ••
• •
• •• • •
• •• ••• •• •
• •
• •• • ••••• ••••• • •
•
• • •• •• •
••• •••••• ••••••••••• ••• •
• • •• • • • •• ••• ••• ••
•• •••••• • •• • •
• •••••••••••••••••••• ••• •• ••• • • • •
•• •• • •••••• •
•
• •••• •••• ••• ••• •
• • •• •••••••••••• •• • •••••• •• • •
• •• •••• •• •• • •• •••• •• •
• ••• •• •• ••
• ••••• •• •• ••
•
•
• • • •• •
•••
55
50
55
60
50
55
55
50
Series lag 4
55
Series lag 3
50
55
Series lag 2
60
60
••
• • •• •
• ••••••• ••
• ••
•••••••• •••• ••
•
•
•
•• ••• • •
••••••••••••••••••••• •
•• ••••• •••••••• •
• •••••••••••••••••••••••••• •
••••••••••••••• •• • •
•••••••••••••••••••••••
••• ••• • •
• •• ••••••••••••••••••••
• •••••••••••••••••••••• •
• ••••••••••
• •••••• • • •
• •• ••
•
•
•••
60
••
•••••
•••••• ••
••••• ••• •
•
•
•
•
•
•
•
•
•
••••••
••••••••••••• •
•• •••••••• •
••••••••••••••••••••• •••
•
•
•
•
•
•
•
•
•
•
•
•••••••••••••••••
••••••••••••
••••••••••••••••••••••
• ••••••••••••••••••••
••••••• •
•••••••••••
•
• ••••
•
••
60
Lag 4
50
60
55
Lag 3
50
60
50
55
60
Lag 6
Lag 7
Lag 8
Lag 9
• •
• • •• •
• •• ••• •
• •• •
• • • • • •• •• •
••• •• •••• ••••••••• ••• •• •
• ••••• ••• • •••••• ••• •
•
••• •
• •• • •••••••• • ••••••••••• •
• ••••••••••••••••
•• •• •
•
• • •• ••••••••••••• ••••••• •• • • ••
• • • ••• ••• •••
•• ••••••••••••••• • ••• ••••• •• •• •
•
••
•
•
•
•
•
• • ••• ••• • • •• • • • • •
• •• • ••
•
••••• • ••••• •
•
•
• • • ••
••
•
•• •••• • •
•
• • • • ••
•• • • •• • •• •
• ••• ••••• ••••••• ••••••••
• ••• ••••••• • •••••• • •••• •
•• •••
• •• •
• • •• • •••••• • • • • •
• •••••••••••••••••••••• ••• ••• •• ••• ••
•• ••• •••••••• ••••••• ••• • ••
••• • ••• ••••• •• ••• •••••••••• •• •
••
• • • • •• • • •
• •• ••••••• •• ••••••••• • • •
•• • • ••
•
••• •• ••• ••
•
•
•••
• •
• ••
••• ••••
•• • •
• • •• •• ••• •
••
•
• ••• ••• ••• ••• •••••••••••••
•••••••••••• ••• ••••••• •
• • •••
• •• •
•• •• ••••••••• ••••••• • ••••••••
•• •••••••••••• • • •• • • • •
• •• •• • ••••••••••••••• ••• •••
•
• • •• •• • • • • •
••• • •••
• •• ••• •• • •• •••••••••••• •
••
•••• •• • • • ••••
•
•
• ••••••• • • •••• • •
• •• • •••••
•
•
•• • • •
•• •
••• ••
• • ••
•
•• • •••
•• •• • •• • •
•••••• •• • •••••••••••••••••
•
•
•
•
• •• •• •
•
•
•
•
•
•
•
• •
••• • ••• •••••••••••••••• ••••• ••
• • •••• • • •• •
• • •• •••• ••••••••••••• ••••••• • •••• •••••
••• • •
•• • •• •••• •• •••••••••••••••••••
••
• ••• •• • ••••••••••
••• •••• • •
• •• •• ••••
•
•
•
•
•
•
••
• • ••••
• •• •••
• • •• • •
••
•• ••
• ••••
• • • • •••
•• • ••• • •••• ••• • •
•
•
•
•
•••
••
• •••••••••
•••• ••••••
•••• •• • ••• ••••••••• •••• ••
• • • •••••••••••• • •••••••• • •• • •
• • •••• •••••••••••••••••• ••••••• •
•• •••
• • • •• ••••••• • •••• ••
• ••••• ••• • •• ••••••••••••••
•••
• •• •• ••••• •••••••••• ••• •
• •••
••••
•
•
•• • • ••••
•••• •••
•
•• •
55
50
55
60
50
55
60
50
55
55
50
Series lag 9
55
Series lag 8
50
55
Series lag 7
50
55
Series lag 6
50
60
60
Lag 5
60
series
60
series
60
series
60
50
55
60
series
Lag 10
Lag 11
Lag 12
Lag 13
Series : timeseries
•• ••
•••• • • •
••
•••• •• •• • •• ••• •
•
• • •••
• •••• ••• • •••••••••••••••
•••• • ••••• •• •••••••
• •• •• ••
••
• • •••••••••• ••••••••••• •• • • • ••
•• •• • •• •
• • •••• • ••
••••• •••• •••••••• •• • •
• •• • • ••••• ••••• • •• • ••
• ••••• ••• ••••••••••••••• • •
••
•
•
•
•
•
• • • •• ••• •• •• ••• •
• ••
•
•• •
•• • • •••• ••••••
• •• •
• • •
• ••
• ••• • •
• • •• • •• •• •• •
• ••• •
•• •••••••
• •••• • •
••• ••• • •
••• ••• • • • •• • •
• • • •• •• •• •••••••••••••• •• • ••
••••• • •• ••••• • •• • ••
•
• ••• •• • •• ••••••• •••••••••••• • •
••
••• • •• •••••• ••• • • •
• •••• ••• ••••••• •••••••••• • •••
• ••
• • • •• • ••••••••••• •• •• • • •
•
•
•
•
•
•
••
• •• • •••••• •••
• •• •
• ••
• • • ••
• • •••
• • • • •• •
••
• •• ••• • • • • • •••••••• ••
•• •• •••
••• •• ••
• •• ••• • • • •• • • • •
• • •••• • ••• •••••• •••• •• ••••
••• • • ••••••• •• •• •
•
•
• ••• •••• ••• •••• ••• •••••••••••• •••••
••
••••••••••••••• • •
••
• ••• • •••••••••• •••••••••• • • • •• • •
•• • • • ••••••••••••• • •••••
•
•
•
•
•
•
•
• •
•• • •• •••••• •••
• •
• ••
• ••
•
• • •• • •
• • ••• • • • •
• •• •• • •• •• • •••••••• •
•••• • • • • •• •• • ••
• • •••• ••• •• •• ••••••• •• ••••
•
• •
•
•
••• •
• • •••••• • •• ••••••• •• •••
•••
• •• • •••• ••••••••••••••••••• ••••
•
•• ••••••••••••• •
•••
•
•• • • •• ••• ••• • •• ••• • • •
• ••••••••••••• •••••
•• • • •• • ••• •• ••
•
•
•
•
•
•
••• •• • •
••• • • •• •
•
••
50
55
series
60
50
55
series
60
50
55
series
60
50
55
60
0.0
ACF
0.4
55
Series lag 13
50
55
Series lag 12
50
55
0.8
series
60
series
60
series
60
series
Series lag 11
60
55
Series lag 10
60
Lag 2
series
50
50
55
Lag 1
timeseries
50
55
50
Series lag 5
60
50
Series lag 1
•
•••
••
•••
••••
•
•
••
•••
•••
••••
•••
•
•
•
•
••••
•••
•••
••••
•
•
•
••••
••••
•••
50
55
50
timeseries
60
Visualization of the Autocorrelation Function
for the Percent CO2 Outlet Gas Data
show.acf(gasrx.tsd)
0
5
10 15
Lag
20
series
1 - 37
Autocorrelation Function
for the Percent CO2 Outlet Gas Data
acf(gasrx.tsd)
0.0
0.2
ACF
0.4
0.6
0.8
1.0
Series : gasry.d$ts
0
5
10
15
20
Lag
1 - 38
RTSERIES iden Command Output
for the Percent CO2 Outlet Gas Data
iden(gasrx.tsd)
CO2 (output)
50
w
55
60
w= Percent CO2
0
50
100
150
200
250
300
time
ACF
6
0.0
-1.0
ACF
0.5
8
1.0
Range-Mean Plot
0
10
20
30
Range
Lag
0.5
0.0
-1.0
2
Partial ACF
1.0
4
PACF
48
50
52
54
Mean
56
58
0
10
20
30
Lag
1 - 39
Download