Internal function to validate the argument preference_order
.
Usage
validate_preference_order(
predictors = NULL,
preference_order = NULL,
preference_order_auto = NULL,
function_name = "collinear::validate_preference_order()",
quiet = FALSE
)
Arguments
- predictors
(optional; character vector) Names of the predictors to select from
df
. If omitted, all numeric columns indf
are used instead. If argumentresponse
is not provided, non-numeric variables are ignored. Default: NULL- preference_order
(optional; string, character vector, output of
preference_order()
). Defines a priority order, from first to last, to preserve predictors during the selection process. Accepted inputs are:"auto" (default): if
response
is not NULL, callspreference_order()
for internal computation.character vector: predictor names in a custom preference order.
data frame: output of
preference_order()
fromresponse
of length one.named list: output of
preference_order()
fromresponse
of length two or more.NULL: disabled.
. Default: "auto"
- preference_order_auto
(required, character vector) names of the predictors in the automated preference order returned by
vif_select()
orcor_select()
- function_name
(optional, character string) Name of the function performing the check. Default: "collinear::validate_preference_order()"
- quiet
(optional; logical) If FALSE, messages generated during the execution of the function are printed to the console Default: FALSE
See also
Other data_validation:
validate_data_cor()
,
validate_data_vif()
,
validate_df()
,
validate_encoding_arguments()
,
validate_predictors()
,
validate_response()
Examples
data(
vi,
vi_predictors
)
#validating example data frame
vi <- validate_df(
df = vi
)
#validating example predictors
vi_predictors <- validate_predictors(
df = vi,
predictors = vi_predictors
)
#tagged as validated
attributes(vi_predictors)$validated
#> [1] TRUE
#validate preference order
my_order <- c(
"swi_max",
"swi_min",
"swi_deviance" #wrong one
)
my_order <- validate_preference_order(
predictors = vi_predictors,
preference_order = my_order,
preference_order_auto = vi_predictors
)
#has my_order first
#excludes wrong names
#all other variables ordered according to preference_order_auto
my_order
#> [1] "swi_max" "swi_min"
#> [3] "koppen_zone" "koppen_group"
#> [5] "koppen_description" "soil_type"
#> [7] "topo_slope" "topo_diversity"
#> [9] "topo_elevation" "swi_mean"
#> [11] "swi_range" "soil_temperature_mean"
#> [13] "soil_temperature_max" "soil_temperature_min"
#> [15] "soil_temperature_range" "soil_sand"
#> [17] "soil_clay" "soil_silt"
#> [19] "soil_ph" "soil_soc"
#> [21] "soil_nitrogen" "solar_rad_mean"
#> [23] "solar_rad_max" "solar_rad_min"
#> [25] "solar_rad_range" "growing_season_length"
#> [27] "growing_season_temperature" "growing_season_rainfall"
#> [29] "growing_degree_days" "temperature_mean"
#> [31] "temperature_max" "temperature_min"
#> [33] "temperature_range" "temperature_seasonality"
#> [35] "rainfall_mean" "rainfall_min"
#> [37] "rainfall_max" "rainfall_range"
#> [39] "evapotranspiration_mean" "evapotranspiration_max"
#> [41] "evapotranspiration_min" "evapotranspiration_range"
#> [43] "cloud_cover_mean" "cloud_cover_max"
#> [45] "cloud_cover_min" "cloud_cover_range"
#> [47] "aridity_index" "humidity_mean"
#> [49] "humidity_max" "humidity_min"
#> [51] "humidity_range" "biogeo_ecoregion"
#> [53] "biogeo_biome" "biogeo_realm"
#> [55] "country_name" "country_population"
#> [57] "country_gdp" "country_income"
#> [59] "continent" "region"
#> [61] "subregion"