predict.VAR: Predict method for objects of class "VAR", "VECM" or "TVAR"

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/predict.VAR.R

Description

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

Usage

1
2
3
4
5
6
## S3 method for class 'TVAR'
predict(object, newdata, n.ahead = 5, newdataTrendStart, ...)

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

Arguments

object

An object of class ‘VAR’, ‘VECM’ or ‘TVAR

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

...

Arguments passed to the unexported ‘VAR.gen’ or ‘TVAR.gen’ function

exoPred

vector/matrix of predictions for the exogeneous variable(s) (with ‘n.ahead’ rows). Only for ‘VAR’/‘VECM’, not for ‘TVAR’.

Details

The forecasts are obtained recursively, and are for the levels of the series.

When providing newdata, newdata has to be ordered chronologically, so that the first row/element is the earliest value.

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.

Value

A matrix of predicted values.

Author(s)

Matthieu Stigler

See Also

lineVar and VECM. VARrep

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
data(barry)
barry_in <- head(barry, -5)
barry_out <- tail(barry, 5)

mod_vecm <- VECM(barry_in, lag=2)
mod_var <- lineVar(barry_in, lag=3)
mod_tvar <- TVAR(barry_in, lag=3, nthresh=1, thDelay=1)

pred_vecm <- predict(mod_vecm)
pred_var  <- predict(mod_var) 
pred_tvar <- predict(mod_tvar)

 
## compare forecasts on a plot
n <- 30
plot(1:n, tail(barry[,1], n), type="l", xlim=c(0,n))
lines((n-5+1):n, pred_var[,1], lty=2, col=2)
lines((n-5+1):n, pred_vecm[,1], lty=2, col=3)
lines((n-5+1):n, pred_tvar[,1], lty=2, col=4) 
legend("bottomright", lty=c(1,2,2,2), col=1:4, legend=c("true", "var", "vecm", "tvar"))

## example for newdata:
all.equal(predict(mod_vecm), predict(mod_vecm, newdata=barry[c(317, 318, 319),]))

tsDyn documentation built on June 4, 2018, 1:04 a.m.