ecmaveback: Backwards selection using an averaged error correction model

ecmavebackR Documentation

Backwards selection using an averaged error correction model

Description

Much like the ecmback function, ecmaveback uses backwards selection to build an error correction model. However, it uses the averaging method of ecmave to build models and then choose variables based on lowest AIC or BIC, or highest adjusted R-squared.

Usage

ecmaveback(
  y,
  xeq,
  xtr,
  includeIntercept = T,
  criterion = "AIC",
  k,
  method = "boot",
  seed = 5,
  weights = NULL,
  keep = NULL,
  ...
)

Arguments

y

The target variable

xeq

The variables to be used in the equilibrium term of the error correction model

xtr

The variables to be used in the transient term of the error correction model

includeIntercept

Boolean whether the y-intercept should be included

criterion

Whether AIC (default), BIC, or adjustedR2 should be used to select variables

k

The number of models or data partitions desired

method

Whether to split data by folds ("fold"), nested folds ("nestedfold"), or bootstrapping ("boot")

seed

Seed for reproducibility (only needed if method is "boot")

weights

Optional vector of weights to be passed to the fitting process

keep

Optional character vector of variables to forcibly retain

...

Additional arguments to be passed to the 'lm' function (careful in that these may need to be modified for ecm or may not be appropriate!)

Details

When inputting a single variable for xeq or xtr, it is important to input it in the format "xeq=df['col1']" in order to retain the data frame class. Inputting such as "xeq=df[,'col1']" or "xeq=df$col1" will result in errors in the ecm function.

If using weights, the length of weights should be one less than the number of rows in xeq or xtr.

This function only works with the 'lm' linear fitter.

Value

an lm object representing an error correction model using backwards selection

See Also

lm

Examples

##Not run

#Use ecm to predict Wilshire 5000 index based on corporate profits, 
#Federal Reserve funds rate, and unemployment rate
data(Wilshire)

#Use 2015-12-01 and earlier data to build models
trn <- Wilshire[Wilshire$date<='2015-12-01',]

#Use backwards selection to choose which predictors are needed 
xeq <- xtr <- trn[c('CorpProfits', 'FedFundsRate', 'UnempRate')]
modelaveback <- ecmaveback(trn$Wilshire5000, xeq, xtr, k = 5)
print(modelaveback)
#Backwards selection chose CorpProfits and FedFundsRate in the equilibrium term, 
#CorpProfits and UnempRate in the transient term.

modelavebackFFR <- ecmaveback(trn$Wilshire5000, xeq, xtr, k = 5, keep = 'UnempRate')
print(modelavebackFFR)
#Backwards selection was forced to retain UnempRate in both terms.


ecm documentation built on May 29, 2024, 8:12 a.m.