Idea Transcript
Time Series Analysis of Aviation , ylab="RPM") • > abline(fit)
Diagnostic Plots • > hist(resid(fit))
• > acf(resid(fit)) • > AIC(fit)
Linear Model with Seasonal Variables •
Linear Model with Seasonal Variables - R • > Seas = cycle(rpm.ts) – Gives the positions in the cycle of each obsv.
• > Time = time(rpm.ts) – Creates the vector of times at which rpm.ts was sampled
• > rpm.lm = lm(rpm.ts~0+Time+factor(Seas)) – Fit rpm.ts to the linear model with seasonal variables
Take a Look at rpm.lm • > summary(rpm.lm) Model Residuals from fitting
Coefficients
Correlogram of rpm.lm Residual • > acf(resid(rpm.lm),lag.max=40)
It indicates strong positive-autocorrelation
Residuals are not pure random numbers, so it should be further modeled
How Random is Random? - White Noise • A time series {wt: t = 1, 2, . . . , n} is discrete white noise (DWN) if the variables w1,w2, . . . ,wn are independent and identically distributed with a mean of zero. • This implies that the variables all have the same variance σ2 and Cor(wi,wj) = 0 for all i ≠ j. • If, in addition, the variables also follow a normal distribution (i.e., wt ∼ N(0, σ2)) the series is called Gaussian white noise.
Simulate White Noise in R • • • •
> set.seed(1) > w = rnorm(100) > plot(w, type = "l") > acf(w)
Random Walk Let {xt} be a time series. Then {xt} is a random walk if • xt = xt−1 + wt where {wt} is a white noise series. Substituting xt−1 = xt−2+wt−1 and then substituting for xt−2, followed by xt−3 and so on gives: • xt = wt + wt−1 + wt−2 + . . . In practice, the series will start at some time t = 1. Hence, • xt = w1 + w2 + . . . + wt
Simulate A Random Walk in R • • • •
> x acf(x) Your plot will be different for sure!
Stationarity •
Auto-Regressive (AR) Models • The series {xt} is an autoregressive process of order p, abbreviated to AR(p), if xt = α1xt−1 + α2xt−2 + . . . + αpxt−p + wt where {wt} is white noise and the αi are the model parameters with αp ≠ 0 for an order p process. • The model is a regression of xt on past terms from the same series; hence the use of the term ‘autoregressive’.
Fit an AR Model • > res.ar=ar(resid(rpm.lm),method="ols") • > res.ar
xt = 0.7153xt−1 + 0.1010xt−2 +0.0579xt−3+ wt
• > acf(res.ar$res[-(1:3)])
OLS: Ordinary Least Square
Moving Average Model •
Simulate an MA Process • > set.seed(1) • > b x acf(x)
Plot Results
First 3 lags with significant correlation
Simulated MA Process
Correlogram of the Simulated MA Process
ARMA Model •
Fit An ARMA Model • > rpm.arma=arima(rpm.ts,order=c(1,0,1)) • > acf(as.numeric(rpm.arma$resid))
Strong seasonal information left in residuals
ARIMA and SARIMA Model • A time series {xt} follows an ARIMA(p, d, q) process if the dth differences of the {xt} series are an ARMA(p, q) process • SARIMA is Seasonal ARIMA model which extends ARIMA model with seasonal terms
Fit A SARIMA Model • > rpm.arima=arima(rpm.ts,order=c(1,1,1), seas=list(order=c(1,0,0),12)) – First c(1,1,1): AR(1), first-order difference, MA(1) – Second c(1,0,0): seasonal terms on AR process, frequency 12
• > acf(as.numeric(rpm.arima$resid))
Forecast • Predicting future values of a time series, xn+m, using the set of present and past values of the time series, x={xn, xn-1, …, x1} • The minimum mean square error predictor of xn+m is xnn m E ( xn m x) • predict(model, newdata) method – model: a model object used for prediction – newdata: value of explanatory variables
Forecast in R • > new.t new.dat rpm.pred=ts(predict(rpm.lm, new.dat)[1:24],start=c(2011,11),freq=12) • > ts.plot(rpm.ts,rpm.pred,lty=1:2)
Plot of Forecast
Forecast with SARIMA Model • > ts.plot( cbind( window(rpm.ts,start = c(1996,1)), predict(rpm.arima,48)$pred ), lty = 1:2)
Homework • Download and Install R with Rstudio • Read An Introduction to R • Download System Passenger - Revenue Aircraft Miles Flown (000) (Jan 1996 - Oct 2011) data from BTS • Read the data into R using Rstudio • Create a time series plot of the data, and plot its auto-correlation correlogram • Decompose the time series and save the plot
Homework (Ctd.) • Construct a linear regression model without seasonal factors, and plot the correlogram of the model’s residual data • Construct a linear regression model with seasonal factors, and identifies the characteristics of the model residual. • Fit an AR model to the model residual of the above model • Forecast the time series data into next 24 months using the seasonal model
Exam Questions • • • •
What are the data elements in a time series? What does auto-correlation mean? What are white noise and random walk? What are stationary models and non-stationary models?