auto_arima_model: ARIMA model with tuned order

Description Usage Arguments Details Value Note Examples

View source: R/arima.R

Description

Creates an ARIMA model that is then fitted to the data as a univariate time series. If further variables are specified in the model, it also includess exogenous variables. The order (p, d, q) is tuned by choosing the one with best fit.

Usage

1
auto_arima_model(p = 5, d = 2, q = 5, intercept = TRUE, ...)

Arguments

p

Maximum order of auto-regressive (AR) terms that is tested to find the best fit (default: 5).

d

Maximum degree of differencing that is tested to find the best fit (default: 2).

q

Maximum order of moving-average (MA) term that is tested to find the best fit (default: 5).

intercept

Boolean value whether to include an intercept term (default: TRUE).

...

Further arguments used when fitting ARIMA model.

Details

Variable importance metrics return the absolute value of the coefficients for the exogenous variables (if any).

Value

Model definition that can then be insered into train.

Note

If one desires an ARIMA model of fixed, pre-defined order, then one needs to switch to auto_arima_model.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(caret)

# without exogenous variables

library(forecast)
data(WWWusage) # from package "forecast"
df <- data.frame(y = as.numeric(WWWusage))

lm <- train(y ~ 1, data = df, method = "lm", trControl = trainDirectFit())
summary(lm)
RMSE(predict(lm, df), df)

arima <- train(y ~ 1, data = df, method = auto_arima_model(), trControl = trainDirectFit())
summary(arima)
RMSE(predict(arima, df), df)

# with exogenous variables

library(vars)
data(Canada)

arima <- train(x = Canada[, -2], y = Canada[, 2], 
               method = auto_arima_model(), trControl = trainDirectFit())

summary(arima)
arimaorder(arima$finalModel) # order of best model

predict(arima, Canada[, -2]) # in-sample predictions
RMSE(predict(arima, Canada[, -2]), Canada[, 2]) # in-sample RMSE

absCoef <- varImp(arima, scale = FALSE) # variable importance (= absolute value of coefficient)
absCoef

plot(absCoef)

sfeuerriegel/caret.ts documentation built on May 29, 2019, 8:01 p.m.