Learn R Programming

tsDyn (version 0.9-44)

predict.VAR: Predict method for objects of class ‘VAR’ or ‘VECM

Description

Forecating the level of a series estimated by ‘VAR’ / ‘VECM

Usage

# S3 method for VAR
predict(object, newdata, n.ahead = 5, newdataTrendStart,
  exoPred = NULL, ...)

Arguments

object

An object of class ‘VAR’ or ‘VECM

newdata

Optional. A new data frame to predict from. This should contain lags of the level of the original series. See Details.

n.ahead

An integer specifying the number of forecast steps.

newdataTrendStart

If ‘newdata’ is provided by the user, and the estimated model includes a trend, this argument specifies where the trend should start

exoPred

vector/matrix of predictions for the exogeneous variable(s) (with ‘n.ahead’ rows)

Arguments passed to the unexported ‘VAR.gen’ function

Value

A matrix of predicted values.

Details

The forecasts are obtained recursively, and are for the levels of the series. For VECM, the forecasts are obtained by transforming the VECM to a VAR (using function VARrep). Note that a VECM(lag=p) corresponds to a VAR(lag=p+1), so that if the user provides newdata for a VECM(lag=p), newdata should actually contain p+1 rows.

See Also

lineVar and VECM. VARrep

A more sophisticated predict function, allowing to do sub-sample rolling predictions: predict_rolling.

Examples

Run this code
# NOT RUN {
data(barry)
mod_vecm <- VECM(barry, lag=2)
pred_VECM <- predict(mod_vecm)


mod_var <- lineVar(barry, lag=3)
pred_VAR <- predict(mod_var)

## compare

plot(tail(barry[,1],50), type="l", xlim=c(0,60))
lines(51:55,pred_VAR[,1], lty=2, col=2)
lines(51:55,pred_VECM[,1], lty=2, col=3)


# note that when providing newdata, newdata has to be ordered chronologically,
# so that the first row/element is the earliest value:
all.equal(predict(mod_vecm), predict(mod_vecm, newdata=barry[c(322, 323, 324),]))
# }

Run the code above in your browser using DataLab