Download - Time series Analysis & fpp package
![Page 1: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/1.jpg)
1
Time Series Analysis & fpp
• Used to predict wind speeds at forecast horizons of 10 minutes to 1 day ahead, based on historical wind speeds (10 minute averages).
• Forecast package: Rob Hyndman• https://www.otexts.org/fpp - good explanations and worked
examples.
Fiona McGroarty Dublin R 24/03/2016
![Page 2: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/2.jpg)
2
Time Series Data
• Forecasting extrapolates trend and seasonal patterns.• Trend : long term increased/decrease.• Seasonal: e.g. daily weekly, yearly (fixed & known length).• Cycle: rises/falls that are not a fixed period (variable & unknown length).
Trend: Generally increasing
Seasonal Pattern: Sharp rise at the end of each year (stockpiling)
• Observations (at regular intervals) sequentially over time.
Fiona McGroarty Dublin R 24/03/2016
![Page 3: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/3.jpg)
3
Autocorrelations
• Correlation: lags 4 & 8 – seasonal pattern, peaks are 4 quarters apart.
• Linear relationship between lagged values of a time series (quarterly beer production):
Lag.plot(beer2, lags=9).
• Corr. Coefficient -1 ≤ r ≤ 1.
• Correlation: lags 2 & 6 – troughs are 2 quarters behind peaks.
Fiona McGroarty Dublin R 24/03/2016
![Page 4: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/4.jpg)
4
Autocorrelations• Plot ACF (acf(beer2)):
• White Noise: 95% of spikes are within ±2/T (T = length of time series=50).
Fiona McGroarty Dublin R 24/03/2016
![Page 5: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/5.jpg)
5
Autocorrelations• Plot ACF (acf(beer2)):
• White Noise: 95% of spikes are within ±2/T (T = length of time series=50).
Fiona McGroarty Dublin R 24/03/2016
![Page 6: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/6.jpg)
6
Simple Forecasts (Benchmarks)
• Naïve method: forecast = value of last observation: naive(beer2, h=11) or rwf(beer2, h=11).
• Average method: forecast = mean of historical data: meanf(beer2, h=11).
• Seasonal naïve: forecast = value of last observation from the previous season
(month/quarter/year ...) snaive(beer2, h=11).
Fiona McGroarty Dublin R 24/03/2016
![Page 7: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/7.jpg)
7
Simple Forecasts (Benchmarks)• Drift: variation on naïve, allow forecast to increase/decrease
over time: rwf (dj2, h=42, drift=TRUE)
Fiona McGroarty Dublin R 24/03/2016
![Page 8: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/8.jpg)
8
Time Series Decomposition
• fit <- stl (elecequip, t.window=15, s.window=“periodic”, robust=TRUE). Plot(fit).
• Time series decomposition: yt = St + Tt + Et or yt = St × Tt × Et Electrical equipment orders. (Seasonal, Trend, Error)
• Set trend window and seasonal window sizes – small values allow more rapid changes.
Fiona McGroarty Dublin R 24/03/2016
![Page 9: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/9.jpg)
9
Forecast: ETS
• Effects of components can be additive (A), multiplicative (M) or ignored (N, none). EG ETS (MAN) forecasts by multiplying errors (M), adding trends (A) and ignoring seasonal effects (N).
SES: Simple Exponential SmoothingHolts Linear Method
Additive Holts-Winter MethodMultiplicative Holts-Winter MethodHolts-Winter damped method
• ETS (ANN) SES with + errors; ETS (MNN) SES with × errors.• Some are numerically unstable e.g. if data contains 0 or neg. values.• ETS(ZZZ) – runs all (stable) ETS models and returns the optimal one.
• ETS (Error, Trend, Seasonal OR ExponenTial Smoothing)
Fiona McGroarty Dublin R 24/03/2016
![Page 10: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/10.jpg)
10
EG: Forecasts using Holt’s method
Fiona McGroarty Dublin R 24/03/2016
![Page 11: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/11.jpg)
11
Forecast: ETS• oildata <- window(oil, start=1996,end=2007) fit <- ets(oildata, model=“ANN”) plot(forecast(fit, h=3), ylab=“Oil (millions of tonnes)”)
• Point forecasts and 80% and 95% prediction intervals.Fiona McGroarty
Dublin R 24/03/2016
![Page 12: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/12.jpg)
12
ARIMA Models
• ARIMA (p, d, q) e.g. ARIMA101 model uses one past time lagged wind speed autocorrelation term (p = 1), is not differentiated (d = 0) and uses one past forecast error (q = 1).
• ARIMA = Auto Regression (detects similarity in the data using time lagged values of the variable) Integrated (the data may have to be differentiated a number of times to make it stationary) Moving Average (using weighted moving average of the past few forecast errors).
• Can specify the ARIMA (p, d, q) model to use, or use auto.arima
Fiona McGroarty Dublin R 24/03/2016
![Page 13: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/13.jpg)
13
ARIMA Models• fit <- auto.arima (usconsumption[,1], seasonal=FALSE plot(forecast(fit, h=10), include=80)
• Best ARIMA model is returned, in this case it’s ARIMA(0,0,3).• fit <- Arima(usconsumption[,1], order=c(0,0,3))
Fiona McGroarty Dublin R 24/03/2016
![Page 14: Time series Analysis & fpp package](https://reader036.vdocuments.mx/reader036/viewer/2022070518/58ec9a181a28ab385a8b45ab/html5/thumbnails/14.jpg)
14
Lots of other things to consider….
• Stationarity of data• Transforming data before forecasting – differentiating…• Error Metrics! Calculate MAE, RMSE,…..
Fiona McGroarty Dublin R 24/03/2016