MoveAheadModel: MoveAheadModel

Description Fields Methods See Also Examples

Description

An autoregressive model which assumes everything stays the same.

Fields

data

A MatrixData containing the data used in fitting of the model.

maxPredCol

The farthest back column from the output value used in prediction.

nsim

The number of stochastic simulations to perform.

predCols

An array of which columns are used in prediction. 1 means the column before the prediction, 2 the one before that etc.

stochastic

A string with the family of stochastic noise to apply to the recursive process. Currently only accepts 'Deterministic' and 'Poisson' as values.

Methods

fit(data)

Fit the model for predicting. This method breaks down the fitting process into two parts, data preparation, and the model fitting.

Arguments
data - The data to use to fit the model. This object should be a MatrixData object.

fit_()

This method is included for compliance with the standard but does nothing. This model does not need to be fit.

Arguments

forecast(newdata = private$.data,steps=1)

Using a model previously fit with fit to predict the next steps columns. This function assumes that all of the data preprocessing has already been taken care of. This function is similar to predict, except that it can predict multiple time steps into the future instead of a single timestep.

Arguments
newdata - The data to forecast from.
steps - The number of timesteps into the future to predict.
Value

private$output This function should both modify and return private$output.

initialize(nsim = 3)

Create a new MoveAheadModel

Arguments
nsim - The number of stochastic simulations to use.

predict(newdata)

Use a model previously fit with fit to predict. This function does not assume any data preprocessing. This function should not, in general need to be overwritten by the user. The main prediction function is predict_, so please modify that function instead if possible.

Arguments
newdata - Optional. The data used to predict. This data should be a MatrixData object.

predictRow(newdata,row,col)

Using a model previously fit with fitRow to predict the rowth row of the next column. This function does not assume any data preprocessing. Since the predict method predicts every row at the the same time, we include this method for predicting only a single row.

Arguments
newdata - Optional. The data use to predict. This can either be a matrix, appropriately formatted lag vector, or NULL to predict based on the data used to fit.
row - The row to predict the value of.
col - This is for internal use only.

predictRow_(row,col=0)

This method predicts a particular row.

Arguments
row - The row to predict
col - This is for internal use.

predict_(col=0)

This method predicts as much as possible about the next time step.

Arguments
col - This is for internal use.

prepareFitData(data)

This method gets data ready for fitting and stores it in the model for later use.

Arguments
data - The data used to fit the model.

prepareForecastData(data)

This method gets data ready to use to forecast and stores it in the model for later use.

Arguments
data - The data to use when forecasting.

prepareOutputData(inputData,steps=0)

This method prepares the output for predict or forecast.

Arguments
inputData - The data being used to predict/forecast.
steps - The number of steps in the forecast. (0 for predict).

preparePredictData(newdata)

This method gets data ready to use to predict and stores it in the model for later use.

Arguments
newdata - The data to use when fitting the model.

See Also

Inherits from : RecursiveForecastModel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
MoveAheadModel <- R6Class(
  classname = 'MoveAheadModel',
  inherit = RecursiveForecastModel,
  private = list(
    .data = IncidenceMatrix$new(),
    newdata = IncidenceMatrix$new(),
    output = ArrayData$new(),
  	.nsim = 3,
    .predCols = c(as.integer(1)),
    .maxPredCol = as.integer(1)
  ),
  public = list(
    initialize = function(nsim = 3){
      private$.nsim = nsim
    },
    fit_ = function(){
      if(self$data$ncol <= self$predCols){
        stop("We cannot go further back than the start of the matrix.")
      }
    },
    predictRow_ = function(row,col=0){
      predict_(col)
    },
    predict_ = function(col=0){
      if('predict_' %in% private$.debug){
        browser()
      }
      if(col == 0){
        col=1:private$output$ncol
      }
      private$output$mutate(
        cols=col,
        data = SimulatedIncidenceMatrix$new(
          private$newdata,
          private$.nsim
        )$simulations
      )
    },
    prepareFitData = function(data){
      private$.data = data$clone(TRUE)
    },
    preparePredictData = function(newdata){
      if('preparePredictData' %in% private$.debug){
        browser()
      }
      private$newdata = SimulatedIncidenceMatrix$new(data=newdata,nsim=self$nsim)
      private$.nrow = private$newdata$nrow
      private$newdata$addColumns(min(self$predCols))
      private$newdata$lag(min(self$predCols),na.rm=FALSE)
      private$newdata$subset(cols=2:private$newdata$ncol)
    },
    prepareForecastData = function(data){
      if(self$data$ncol <= self$predCols){
        stop("We cannot go further back than the start of the matrix.")
      }
      private$newdata = data$clone(TRUE)
      private$.nrow = private$newdata$nrow
      private$newdata$addColumns(min(self$predCols))
      private$newdata$lag(min(self$predCols),na.rm=TRUE)
    },
    prepareOutputData = function(inputData,steps=0){
      private$output = SimulatedIncidenceMatrix$new(inputData,private$.nsim)
      if(steps > 0){
        private$output$addColumns(steps)
      }
    }
  ),
  active = list(
    nsim = function(value){
      private$defaultActive(type='private',name='.nsim',val=value)
    }
  )
)

HopkinsIDD/ForecastFramework documentation built on Nov. 10, 2019, 2:15 a.m.