#' Functions for HDeconometricsVAR objects
#'
#' Functions for HDeconometricsVAR objects
#'
#' @param object HDeconometricsVAR object generated by the functions lbvar or HDvar.
#' @param h Forecasting horizon. If h=0 returns the fitted values.
#' @param newdata Exogenous variables to compute the predictions. If the model has exogenous controls (xreg) newdata must be supplied.
#' @param type equation to extract coefficients by equation and block to extract blocks like cons. lags and xreg coefficients.
#' @param ... Arguments for other methods.
#' @export
#' @examples
#' ## == This example uses the Brazilian inflation data from
#' #Garcia, Medeiros and Vasconcelos (2017) == ##
#' data("BRinf")
#' Y=BRinf[,1:59]# remove expectation variables
#'
#' modelB=lbvar(Y,p=4)
#' predict(modelB,h=10)
#'
#' # take a look at the coefficients
#' eq=coef(modelB,type="equation")
#' block=coef(modelB,type="block")
#' block$Lag1
#'
#' @references
#' Garcia, Medeiros and Vasconcelos (2017).
#' @seealso \code{\link{HDvar}}, \code{\link{lbvar}}
predict.HDeconometricsVAR=function(object,h=0,newdata=NULL,...){
if(h==0){
return(fitted(object))
}
p = object$p
b = t(object$coef.by.equation)
aux = stats::embed(object$Y, p)
aux = aux[nrow(aux), ]
N = ncol(object$Y)
prev.store = matrix(NA, h, N)
exog=length(object$xreg)
if(!is.matrix(newdata) & exog!=0){
newdata=as.matrix(newdata)
}
for (i in 1:h) {
if(exog>0){
prev = c(1, aux,newdata[i,]) %*% b
}else{
prev = c(1, aux) %*% b
}
prev.store[i, ] = prev
aux = c(prev, head(aux, length(aux) - N))
}
final.prediction = prev.store
colnames(final.prediction) = colnames(object$Y)
return(final.prediction)
}
#' @rdname predict.HDeconometricsVAR
#' @export
coef.HDeconometricsVAR=function(object,type="equation",...){
if(type=="equation") return(object$coef.by.equation)
if(type=="block") return(object$coef.by.block)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.