Open
Description
This example the recipe in the vignette
library(recipes)
library(epipredict)
jhu <- case_death_rate_subset %>%
dplyr::filter(
time_value >= "2021-06-04",
time_value <= "2021-12-31",
geo_value %in% c("ca", "fl", "tx", "ny", "nj")
) %>%
mutate(geo_value_factor = as.factor(geo_value))
r <- recipe(jhu) %>%
add_role(time_value, new_role = "predictor") %>%
step_dummy(geo_value_factor, role = "predictor") %>%
step_growth_rate(case_rate, role = "none", prefix = "gr_") %>%
step_epi_lag(starts_with("gr_"), lag = c(0, 7, 14)) %>%
step_epi_ahead(starts_with("gr_"), ahead = 7, role = "none") %>%
# note recipes::step_cut() has a bug in it, or we could use that here
step_mutate(
response = cut(
ahead_7_gr_7_rel_change_case_rate,
breaks = c(-Inf, -0.2, 0.25, Inf) / 7, # division gives weekly not daily
labels = c("down", "flat", "up")
),
role = "outcome"
) %>%
step_rm(has_role("none"), has_role(NA)) %>%
step_epi_naomit()
r
#>
#> ── Epi Recipe ──────────────────────────────────────────────────────────────────
#>
#> ── Inputs
#> Number of variables by role
#> predictor: 1
#> geo_value: 1
#> time_value: 1
#> undeclared role: 3
#>
#> ── Operations
#> $terms
#> <list_of<quosure>>
#>
#> [[1]]
#> <quosure>
#> expr: ^geo_value_factor
#> env: 0x12d1a6128
#>
#>
#> $role
#> [1] "predictor"
#>
#> $trained
#> [1] FALSE
#>
#> $one_hot
#> [1] FALSE
#>
#> $preserve
#> [1] FALSE
#>
#> $naming
#> function (var, lvl, ordinal = FALSE, sep = "_")
#> {
#> args <- vctrs::vec_recycle_common(var, lvl)
#> var <- args[[1]]
#> lvl <- args[[2]]
#> if (!ordinal) {
#> nms <- paste(var, make.names(lvl), sep = sep)
#> }
#> else {
#> nms <- paste0(var, names0(length(lvl), sep))
#> }
#> nms
#> }
#> <bytecode: 0x12d048b48>
#> <environment: namespace:recipes>
#>
#> $levels
#> NULL
#>
#> $keep_original_cols
#> [1] FALSE
#>
#> $skip
#> [1] FALSE
#>
#> $id
#> [1] "dummy_rgGr9"
#>
#> attr(,"class")
#> [1] "step_dummy" "step"
#> $role
#> [1] "outcome"
#>
#> $trained
#> [1] FALSE
#>
#> $inputs
#> <list_of<quosure>>
#>
#> $response
#> <quosure>
#> expr: ^cut(ahead_7_gr_7_rel_change_case_rate, breaks = c(-Inf, -0.2, 0.25,
#> Inf) / 7, labels = c("down", "flat", "up"))
#> env: 0x12d1a63c8
#>
#>
#> $skip
#> [1] FALSE
#>
#> $id
#> [1] "mutate_MVXkG"
#>
#> attr(,"class")
#> [1] "step_mutate" "step"
#> $terms
#> <list_of<quosure>>
#>
#> [[1]]
#> <quosure>
#> expr: ^has_role("none")
#> env: 0x12d1a6470
#>
#> [[2]]
#> <quosure>
#> expr: ^has_role(NA)
#> env: 0x12d1a6470
#>
#>
#> $role
#> [1] NA
#>
#> $trained
#> [1] FALSE
#>
#> $removals
#> NULL
#>
#> $skip
#> [1] FALSE
#>
#> $id
#> [1] "rm_mV3xQ"
#>
#> attr(,"class")
#> [1] "step_rm" "step"
#> 1. Calculating growth_rate for: case_rate by rel_change
#> 2. Lagging: starts_with("gr_") by 0, 7, 14
#> 3. Leading: starts_with("gr_") by 7
#> 4. • Removing rows with NA values in: all_predictors()
#> 5. • Removing rows with NA values in: all_outcomes()
Metadata
Metadata
Assignees
Labels
No labels