Skip to contents

This function creates an unfit workflow for use with arx_classifier(). It is useful if you want to make small modifications to that classifier before fitting and predicting. Supplying a trainer to the function may alter the returned epi_workflow object but can be omitted.

Usage

arx_class_epi_workflow(
  epi_data,
  outcome,
  predictors,
  trainer = parsnip::logistic_reg(),
  args_list = arx_class_args_list()
)

Arguments

epi_data

An epi_df object

outcome

A character (scalar) specifying the outcome (in the epi_df). Note that as with arx_forecaster(), this is expected to be real-valued. Conversion of this data to unordered classes is handled internally based on the breaks argument to arx_class_args_list(). If discrete classes are already in the epi_df, it is recommended to code up a classifier from scratch using epi_recipe().

predictors

A character vector giving column(s) of predictor variables. This defaults to the outcome. However, if manually specified, only those variables specifically mentioned will be used. (The outcome will not be added.) By default, equals the outcome. If manually specified, does not add the outcome variable, so make sure to specify it.

trainer

A {parsnip} model describing the type of estimation. For now, we enforce mode = "classification". Typical values are parsnip::logistic_reg() or parsnip::multinom_reg(). More complicated trainers like parsnip::naive_Bayes() or parsnip::rand_forest() can also be used. May be NULL if you'd like to decide later.

args_list

A list of customization arguments to determine the type of forecasting model. See arx_class_args_list().

Value

An unfit epi_workflow.

See also

Examples

library(dplyr)
jhu <- case_death_rate_subset %>%
  filter(time_value >= as.Date("2021-11-01"))

arx_class_epi_workflow(jhu, "death_rate", c("case_rate", "death_rate"))
#> 
#> ══ Epi Workflow ════════════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: logistic_reg()
#> Postprocessor: Frosting
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 
#> 8 Recipe steps.
#> 1. step_growth_rate()
#> 2. step_epi_lag()
#> 3. step_epi_lag()
#> 4. step_epi_ahead()
#> 5. step_mutate()
#> 6. step_naomit()
#> 7. step_naomit()
#> 8. step_training_window()
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> Logistic Regression Model Specification (classification)
#> 
#> Computational engine: glm 
#> 
#> 
#> ── Postprocessor ───────────────────────────────────────────────────────────────
#> 
#> 3 Frosting layers.
#> 1. layer_predict()
#> 2. layer_add_forecast_date()
#> 3. layer_add_target_date()
#> 

arx_class_epi_workflow(
  jhu,
  "death_rate",
  c("case_rate", "death_rate"),
  trainer = multinom_reg(),
  args_list = arx_class_args_list(
    breaks = c(-.05, .1), ahead = 14,
    horizon = 14, method = "linear_reg"
  )
)
#> 
#> ══ Epi Workflow ════════════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: multinom_reg()
#> Postprocessor: Frosting
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 
#> 8 Recipe steps.
#> 1. step_growth_rate()
#> 2. step_epi_lag()
#> 3. step_epi_lag()
#> 4. step_epi_ahead()
#> 5. step_mutate()
#> 6. step_naomit()
#> 7. step_naomit()
#> 8. step_training_window()
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> Multinomial Regression Model Specification (classification)
#> 
#> Computational engine: nnet 
#> 
#> 
#> ── Postprocessor ───────────────────────────────────────────────────────────────
#> 
#> 3 Frosting layers.
#> 1. layer_predict()
#> 2. layer_add_forecast_date()
#> 3. layer_add_target_date()
#>