Skip to contents

Computes the the minimum, mean, maximum, and quantiles 0.05, 0.25, median (0.5), 0.75, and 0.95 of the column "vif" in the output of vif_df().

Usage

vif_stats(df = NULL, predictors = NULL, quiet = FALSE, ...)

Arguments

df

(required; dataframe, tibble, or sf) A dataframe with responses (optional) and predictors. Must have at least 10 rows for pairwise correlation analysis, and 10 * (length(predictors) - 1) for VIF. Default: NULL.

predictors

(optional; character vector or NULL) Names of the predictors in df. If NULL, all columns except responses and constant/near-zero-variance columns are used. Default: NULL.

quiet

(optional; logical) If FALSE, messages are printed. Default: FALSE.

...

(optional) Internal args (e.g. function_name for validate_arg_function_name, a precomputed correlation matrix m, or cross-validation args for preference_order).

Value

dataframe with columns method with the value "vif", statistic with the statistic name, and value.

See also

Examples

data(vi_smol, package = "spatialData")
data(vi_predictors, package = "spatialData")
vi_predictors_numeric <- identify_numeric_variables(
  df = vi_smol,
  predictors = vi_predictors
)$valid

# ## OPTIONAL: parallelization setup
# ## irrelevant when all predictors are numeric
# ## only worth it for large data with many categoricals
# future::plan(
#   future::multisession,
#   workers = future::availableCores() - 1
# )

# ## OPTIONAL: progress bar
# progressr::handlers(global = TRUE)

x <- vif_stats(
  df = vi_smol,
  predictors = vi_predictors_numeric
)
#> 
#> collinear::vif_stats()
#> └── collinear::vif_df()
#>     └── collinear::validate_arg_df()
#>         └── collinear::drop_geometry_column(): dropping geometry column from 'df'.

x
#>   method     statistic    value
#> 1    vif             n  47.0000
#> 2    vif       minimum   2.1230
#> 3    vif quantile_0.05   3.4768
#> 4    vif quantile_0.25  52.6007
#> 5    vif          mean 213.8434
#> 6    vif        median 192.5452
#> 7    vif quantile_0.75 358.5660
#> 8    vif quantile_0.95 501.9424
#> 9    vif       maximum 564.8668

## OPTIONAL: disable parallelization
#future::plan(future::sequential)