R/polyDlmForecast.main.R

Defines functions polyDlmForecast.main

polyDlmForecast.main <- function(model , x , h = 1 , epsilon = NULL){
  if (is.null(epsilon) == TRUE){
    epsilon <- array(0, h)
  }
  forecasts <- array(NA, h)
  coefs <- model$model$coefficients
  n <- nrow(model$designMatrix.x)
  m <- ncol(model$designMatrix.x) # The first column is y.t
  x.obs <- model$designMatrix.x[n , 2:m] # The last row of design matrix
  x.obs <- guyrot(x.obs,1)
  x.obs[1] <- x[1]  # New x-vector is created
  x.obs <- unlist(x.obs)
  s <- length(coefs) - 1 
  q <- m - 2 
  tr.matrix <- model$transformation.matrix
  for (i in 1:h){
    z <- c(1 , tr.matrix %*% x.obs)
    forecasts[i] <- as.vector(coefs)%*%z + epsilon[i]
    x.obs <- guyrot(x.obs,1)
    if (i != h){
      x.obs[1] <- x[(i+1)]
    }
  }
  return(list(forecasts = forecasts))
}

Try the dLagM package in your browser

Any scripts or data that you put into this service are public.

dLagM documentation built on Oct. 2, 2023, 9:07 a.m.