Skip to content
Snippets Groups Projects
quantile_predict.R 893 B
Newer Older
  • Learn to ignore specific revisions
  • #' @title quantile_prediction
    #'
    #' @description This function plots the quantiles
    #' @param Lfor List of the data needed to plot
    #' @export
    #' @examples
    #' plotprob()
    
    quantile_predict <- function(model, datatr){
        Yhat <- lapply(model$tau, function(q){
            
            yHat <- sapply(model$kseq, function(k){
                ## Setup the design matrix for k step
                X <- as.data.frame(subset(datatr, kseq=k))
                ## Lag them to match to the 
    
    hgb's avatar
    hgb committed
                X <- onlineforecast:::lagdf.matrix(X, k)
    
                yhat <- as.numeric(rep(NA, nrow(X)))
    
    hgb's avatar
    hgb committed
                
                for(i in ((1):nrow(X))){
                    yhat[i] <- t(as.numeric(X[i,])) %*% model$beta[[paste0("q",q)]][[paste0("k",k)]][i,]
    
                }
    
                return(yhat)
            })
            nams(yHat) <- pst("k", model$kseq)
            return(yHat)
        })
        names(Yhat) <- pst("q", model$tau)
        return(Yhat)
    }