intro to forecasting in r - part 4

14
Intro to Forecasting in R - Part 4 Houston R Users Group Ed Goodwin, CFA

Upload: egoodwintx

Post on 08-Jan-2017

480 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Intro to Forecasting in R - Part 4

Houston R Users Group Ed Goodwin, CFA

The story so far…• time series classes in R

• simple and naive forecasts

• simple linear regressions

• dummy variables

• data transformations

• scaling series

• stationarity and autocorrelation

• decomposing time series

• Holt-Winters

Stationarity

• A stationary time series is one whose properties do not depend on the time at which the series is observed.

• No trends, or seasonality.

Differencing

• Use the diff( ) function

• Inputs are lag (lag window) and differences (order of differences)

• Order is whether it’s first derivative difference, second derivative, etc.

Differences (contd.)• Differences variable is the

order of the differences…i.e. how many levels down the differences are

• Think of it as the differences of the differences

Unit Root Tests• Test to see if data is

non-stationary

• Augmented Dickey-Fuller test is a popular option (adf.test function)

• ADF assumes that data is non-stationary, and tests the likelihood of the alternative hypothesis

tsdisplay( )Shows time series and ACF and PACF displays

ARIMA Models

• Autoregressive (AR) models forecast the variable of interest based on past historic data of the variable itself

• Moving Average (MA) models use prior forecast errors to create a regression model

• ARIMA models combine these two types of models…AutoRegressive Integrated Moving Averages

ARIMA (contd.)

ARIMA models are the linear subset of ETS models.

ARIMA (contd.)

The standard ARIMA model is called an ARIMA(p,d,q) where:

• p = order of the autoregressive part

• d = degree of first differencing involved

• q = order of the moving average part

This model is non-seasonal

Sample ARIMA Models• White noise - ARIMA(0,0,0)

• Random walk - ARIMA(0,1,0)

Auto Selection of ARIMA Models in R

• auto.arima( )

• selects an ARIMA(0,0,3) model

Seasonal ARIMA models• ARIMA (p,d,q) (P,D,Q)m where m is the number of

periods in a season

• You can use auto.arima( ) to choose these as well

Seasonal ARIMA Forecast