Skip to contents

The DiseasyModelRegression module implements common structure and functionality to regression class of models beyond the model structure provided by ?DiseasyModel.

Most notably, the model module implements the $get_results() method. This implementation requires the subclass to implement the $fit_regression(), $get_prediction() and $update_formula() methods.

The $fit_regression() method should fit the regression model to the training data. In the case of a GLM model, this would be a call to stats::glm.

The $get_prediction() method should predict the future values of the observable. In the case of a GLM model, this would be a call to stats::predict.

The $update_formula() method should update the formula based on the stratifications. If the model should flexibly adapt to different stratifications, this method should be implemented. See ?DiseasyModelGLM and ?DiseasyModelBRM for examples of how this can be done.

Value

A new instance of the DiseasyModelRegression R6 class.

Super classes

diseasy::DiseasyBaseModule -> diseasy::DiseasyModel -> DiseasyModelRegression

Active bindings

formula

(formula)
The base formula of the module. Stratification features extend this base formula. Read-only.

family

(family)
The family used in the regression fit (see glm or brms). Read-only.

Methods

Inherited methods


Method new()

Creates a new instance of the DiseasyModelRegression R6 class. This module is typically not constructed directly but rather through DiseasyModel* classes, such as DiseasyModelG0.

Usage

DiseasyModelRegression$new(formula, family, ...)

Arguments

formula

(character)
A character string that is passed to stats::as.formula via glue (see details).

family

(family)
stats::family object passed to the regression call.

...

parameters sent to DiseasyModel R6 constructor.

parameters

(named list())

  • training_length (named numeric(3))
    The number of days that should be included in the training splits of the data for the model. Allowed splits are: "training", "testing", and "validation".

Details

The observable will change at run time and we therefore cannot define a static formula. We can use "{observable}" in our formula which will then be translated at run time. For example, if the requested observable is "n_hospital" and the formula is "{observable} ~ 1", then at run time, the formula will translate to "n_hospital ~ 1".

Furthermore the stratification can also change at run time, so the model should incorporate a update_formula(stratification) function that accounts for changes in stratification.


Method get_results()

The primary method used to request model results of a given observable at a given stratification

Usage

DiseasyModelRegression$get_results(
  observable,
  prediction_length,
  quantiles = NULL,
  stratification = NULL
)

Arguments

observable

(character)
The observable to provide data or prediction for.

prediction_length

(numeric)
The number of days to predict. The prediction start is defined by last_queryable_date of the ?DiseasyObservables R6 class.

quantiles

(list(numeric))
If given, results are returned at the quantiles given.

stratification

(list(quosures) or NULL)
Use rlang::quos(...) to specify stratification. If given, expressions in stratification evaluated to give the stratification level.

Returns

A tibble tibble::tibble with predictions at the level specified by stratification level. In addition to stratification columns, the output has the columns:

- date (Date) specifying the date of the prediction.
- realisation_id (character) giving a unique id for each realization in the ensemble.
- weight (numeric) giving the weight of the realization in the ensemble.


Method plot()

Plot the predictions from the current model

Usage

DiseasyModelRegression$plot(
  observable,
  prediction_length,
  stratification = NULL
)

Arguments

observable

(character)
The observable to provide data or prediction for.

prediction_length

(numeric)
The number of days to predict. The prediction start is defined by last_queryable_date of the ?DiseasyObservables R6 class.

stratification

(list(quosures) or NULL)
Use rlang::quos(...) to specify stratification. If given, expressions in stratification evaluated to give the stratification level.


Method clone()

The objects of this class are cloneable with this method.

Usage

DiseasyModelRegression$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

  # This module cannot be constructed directly but should instead be used to
  # inherit from when creating a new model class.