recursive-forecasts: Pseudo out-of-sample forecasts

Description Usage Arguments Details Value Author(s) References Examples

Description

Creates a sequence of pseudo out-of-sample forecasts.

Usage

1
2
recursive_forecasts(model, dataset, R,
                    window = c("recursive", "rolling", "fixed"),...)

Arguments

model

A function that takes dataset as its first argument. model must return an object with a predict method.

dataset

A data frame with more than R observations

R

An integer: the size of the estimation window.

window

One of "rolling", "recursive", or "fixed" describing the estimation strategy

...

Additional arguments to pass to model

Details

Uses model to create a sequence of forecasts or forecast errors for observations R+1,...,nrow(dataset). For the "rolling" window, each forecast comes from the model estimated with the previous R observations. For the "recursive" window, each forecast uses all of the previous observations. And for the "fixed" window, each forecast uses the first R observations.

Value

A vector of length nrow(dataset) - R, containing the forecasts.

Author(s)

Gray Calhoun gcalhoun@iastate.edu

References

Calhoun, G. 2011, Documentation appendix: An asymptotically normal out-of-sample test of equal predictive accuracy for nested models. Unpublished manuscript.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
d <- data.frame(x = rnorm(15), y = rnorm(15))
ols <- function(d) lm(y ~ x, data = d)
## Basic Usage:
recursive_forecasts(ols, d, 4, "recursive")

## Illustrate different estimation windows by comparing forecasts for
## observation 11 (note that the forecast for observation 11 will be the
## 7th element that apply.oos returns in this example)
newd <- d[11,]


all.equal(predict(lm(y ~ x, data = d[7:10,]), d[11,]),
          recursive_forecasts(ols, d, 4, "rolling")[7])



all.equal(predict(lm(y ~ x, data = d[1:10,]), d[11,]),
          recursive_forecasts(ols, d, 4, "recursive")[7])



all.equal(predict(lm(y ~ x, data = d[1:4,]), d[11,]),
          recursive_forecasts(ols, d, 4, "fixed")[7])

grayclhn/oosanalysis-R-library documentation built on May 17, 2019, 8:33 a.m.