When producing conditional estimates from a regression model, it is often useful to set variables not of interest to their mode for factors and mean or median for numerics when creating the newdata object, and combine these with all levels for factors of interest.
ff_expand(.data, ..., cont = "mean")
finalfit_expand(.data, ..., cont = "mean")
A data frame or tibble.
Factors to expand.
One of "mean" or "median": the summary estimate for continuous variables.
A data frame or tibble with the mode for factors and mean/median for continuous variables, with given factors expanded to include all levels.
library(dplyr)
colon_s %>%
select(-hospital) %>%
ff_expand(age.factor, sex.factor)
#> # A tibble: 6 × 31
#> age.factor sex.factor id rx sex age obstruct perfor adhere nodes
#> <fct> <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 <40 years Female 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> 2 <40 years Male 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> 3 40-59 years Female 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> 4 40-59 years Male 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> 5 60+ years Female 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> 6 60+ years Male 465 Obs 0.521 59.8 0.194 0.0291 0.145 3.66
#> # ℹ 21 more variables: status <dbl>, differ <dbl>, extent <dbl>, surg <dbl>,
#> # node4 <dbl>, time <dbl>, rx.factor <fct>, obstruct.factor <fct>,
#> # perfor.factor <fct>, adhere.factor <fct>, differ.factor <fct>,
#> # extent.factor <fct>, surg.factor <fct>, node4.factor <fct>,
#> # status.factor <fct>, loccomp <dbl>, loccomp.factor <fct>, time.years <dbl>,
#> # mort_5yr <fct>, age.10 <dbl>, mort_5yr.num <dbl>