Skip to content
Snippets Groups Projects
Select Git revision
  • d51c07a0a60176309eb9db2f6c49841b60be0ebb
  • master default protected
  • feature/quantileforecast
  • develop
  • add_kseq
5 results

forecastmodel.R

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    forecastmodel.R 16.89 KiB
    #' @export
    forecastmodel <- R6::R6Class("forecastmodel", public = list(
        #----------------------------------------------------------------
        # Fields used for setting up the model
        # 
        # The expression (as character) used for generating the regprm
        regprmexpr = NA,
        # Regression parameters for the function used for fitting (rls, ls, etc.)
        regprm = list(), 
        # The off-line parameters
        prmbounds = as.matrix(data.frame(lower=NA, init=NA, upper=NA)),
        # List of inputs (which are R6 objects) (note the "cloning of list of reference objects" issue below in deep_clone function)
        inputs = list(),
        # Name of the output
        output = "y",
        # The range of the output to be used for cropping the output
        outputrange = NA,
        #----------------------------------------------------------------
    
        
        #----------------------------------------------------------------
        # Fields to be used when the model is fitted
        #
        # The horizons to fit for
        kseq = NA,
        # The (transformation stage) parameters (only the ones set in last call of insert_prm())
        prm = NA,
        # Stores the maximum lag for AR terms
        maxlagAR = NA,
        # Stores the maxlagAR past values of y for the update when new obs becomes available
        yAR = NA,
        # The fits, one for each k in kseq (simply a list with the latest fit)
        Lfits = list(),
        # Transformed input data (data.list with all inputs for regression)
        datatr = NA,
        #----------------------------------------------------------------
    
        
        #----------------------------------------------------------------
        # Contructor function
        initialize = function(){},
        #----------------------------------------------------------------
    
        
        #----------------------------------------------------------------    
        # Add inputs to the model
        add_inputs = function(...){
            dots <- list(...)
            for (i in 1:length(dots)){
                self$inputs[[ nams(dots)[i] ]] <- input_class$new(dots[[i]], model=self)
            }
        },
        #----------------------------------------------------------------
    
        #----------------------------------------------------------------
        # Add the expression (as character) which generates the regression parameters
        add_regprm = function(regprmexpr){
            self$regprmexpr <- regprmexpr
            self$regprm <- eval(parse(text = self$regprmexpr))
        },
        #----------------------------------------------------------------
    
        
        #----------------------------------------------------------------
        # Add the transformation parameters and bounds for optimization
        add_prmbounds = function(...) {
            dots <- list(...)
            for (i in 1:length(dots)) {
                nm <- names(dots)[i]
                if (nm %in% rownames(self$prmbounds)) {