pred.given.mrf: Macroeconomic Random Forest Prediction Function

Description Usage Arguments Value Examples

View source: R/MRF_v210403.R

Description

This function predicts y for new data using a previously estimated MRF object. This allows for prediction without re-estimating the model, and doing so in separate functions (which is customary for ML packages). While this addition is redundant for direct forecasting (which should all be done within MRF function for more efficient memory management), it allows for iterative (potentially multivariate) forecasting. However, in that scenario, straightforward residuals-based simulation methods (like in Milunovich (2019)) need to be used since the forecasting function is nonlinear. I recommend using out-of-bag residuals for that sake, which can be easily obtained from MRF's output (y[t]-X[t]beta[t]).

Usage

1
pred.given.mrf(mrf.output,newdata)

Arguments

mrf.output

Some output from running MRF function (and setting oos.pos = c() and keep.forest=TRUE).

y.pos

A new vector/matrix of data excluding y, which is assumed to the first row of the matrix when you previously ran MRF function. Predictors matrix must have column names, both when you run this and the MRF function.

Value

output

Returns predictions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data=matrix(rnorm(15*200),200,15)
colnames(data)=paste('X_',1:ncol(data),sep='')

#DGP
library(pracma)
X=data[,1:3]
y=crossprod(t(X),rep(1,3))*(1-0.5*I(c(1:200)>75))+rnorm(200)/2
trend=1:200
data.in=cbind(y,data,trend)
colnames(data.in)[1]='y'
mrf.output=MRF(data=data.in[-c(151:200),],y.pos=1,x.pos=2:4,S.pos=2:ncol(data.in),oos.pos=c(),trend.push=4,quantile.rate=0.3,keep.forest=TRUE)

pred.given.mrf(mrf.output,as.data.frame(data.in[151:200,-1]))

philgoucou/macrorf documentation built on Dec. 22, 2021, 7:48 a.m.