Learn R Programming

Eplot (version 1.0)

linpred: linpred

Description

Provides linear regression based predictions from a y~x type model using recursive or rolling regression.

Usage

linpred(y, x, h = 1, wind = NULL, rr = c("Rec"))

Arguments

y
a series to be predicted
x
a numeric or matrix of explanatory variables
h
The horizon for which you would like to have the prediction for (see details)
wind
the size of the rolling window or the initial training period if recursive is used
rr
recursive or rolling window? Possible values are c("Rec","Rol")

Value

vector of prediction values with the same dimension as the original series. The first wind values are NA's

Details

The training is done using the direct method: $y_{1 : (t+h-1)} = \beta x_{1:(t-1)} + \varepsilon_{1:(t+h-1)} $ and the forecast is made at time (t+h) as $\widehat{y}_{t+h} = \widehat{\beta} x_t$.

Examples

Run this code
x = rnorm(100)
lx <- lagmat(x,2)
tail(lx)
tail(x)
out <- linpred(x,lx)
plott(x, return.to.default=FALSE)
plott(out,add=TRUE,col=2)

Run the code above in your browser using DataLab