From an initial model formula, create a list of formulas that exclude each predictor.
leave_var_out_formulas(formula, data, full_model = TRUE, ...)A model formula that contains at least two predictors.
A data frame.
A logical; should the list include the original formula?
Options to pass to stats::model.frame()
A named list of formulas
The new formulas obey the hierarchy rule so that interactions without main effects are not included (unless the original formula contains such terms).
Factor predictors are left as-is (i.e., no indicator variables are created).
data(penguins, package = "modeldata")
leave_var_out_formulas(
bill_length_mm ~ .,
data = penguins
)
#> $species
#> bill_length_mm ~ island + bill_depth_mm + flipper_length_mm +
#> body_mass_g + sex
#> <environment: base>
#>
#> $island
#> bill_length_mm ~ species + bill_depth_mm + flipper_length_mm +
#> body_mass_g + sex
#> <environment: base>
#>
#> $bill_depth_mm
#> bill_length_mm ~ species + island + flipper_length_mm + body_mass_g +
#> sex
#> <environment: base>
#>
#> $flipper_length_mm
#> bill_length_mm ~ species + island + bill_depth_mm + body_mass_g +
#> sex
#> <environment: base>
#>
#> $body_mass_g
#> bill_length_mm ~ species + island + bill_depth_mm + flipper_length_mm +
#> sex
#> <environment: base>
#>
#> $sex
#> bill_length_mm ~ species + island + bill_depth_mm + flipper_length_mm +
#> body_mass_g
#> <environment: base>
#>
#> $everything
#> bill_length_mm ~ .
#> <environment: 0x556f4f540ad8>
#>
leave_var_out_formulas(
bill_length_mm ~ (island + sex)^2 + flipper_length_mm,
data = penguins
)
#> $island
#> bill_length_mm ~ sex + flipper_length_mm
#> <environment: base>
#>
#> $sex
#> bill_length_mm ~ island + flipper_length_mm
#> <environment: base>
#>
#> $flipper_length_mm
#> bill_length_mm ~ island + sex + island:sex
#> <environment: base>
#>
#> $`island:sex`
#> bill_length_mm ~ island + sex + flipper_length_mm
#> <environment: base>
#>
#> $everything
#> bill_length_mm ~ (island + sex)^2 + flipper_length_mm
#> <environment: 0x556f4f540ad8>
#>
leave_var_out_formulas(
bill_length_mm ~ (island + sex)^2 + flipper_length_mm +
I(flipper_length_mm^2),
data = penguins
)
#> $island
#> bill_length_mm ~ sex + flipper_length_mm + I(flipper_length_mm^2)
#> <environment: base>
#>
#> $sex
#> bill_length_mm ~ island + flipper_length_mm + I(flipper_length_mm^2)
#> <environment: base>
#>
#> $flipper_length_mm
#> bill_length_mm ~ island + sex + island:sex
#> <environment: base>
#>
#> $`I(flipper_length_mm^2)`
#> bill_length_mm ~ island + sex + flipper_length_mm + island:sex
#> <environment: base>
#>
#> $`island:sex`
#> bill_length_mm ~ island + sex + flipper_length_mm + I(flipper_length_mm^2)
#> <environment: base>
#>
#> $everything
#> bill_length_mm ~ (island + sex)^2 + flipper_length_mm + I(flipper_length_mm^2)
#> <environment: 0x556f4f540ad8>
#>