Selects predictors that are not linear combinations of other predictors by using computing their variance inflation factors (VIF). Allows the user to define an order of preference for the selection of predictors. Warning: variables in preference.order not in colnames(x), and non-numeric columns are removed silently from x and preference.order. The same happens with rows having NA values (na.omit() is applied). The function issues a warning if zero-variance columns are found.

auto_vif(
  x = NULL,
  preference.order = NULL,
  vif.threshold = 5,
  verbose = TRUE
)

Arguments

x

A data frame with predictors or the result of auto_cor(). Default: NULL.

preference.order

a character vector with columns names of x ordered by the user preference, Default: NULL.

vif.threshold

Numeric between 2.5 and 10 defining the selection threshold for the VIF analysis. Higher numbers result in a more relaxed variable selection. Default: 5.

verbose

Logical. if TRUE, describes the function operations to the user. Default:: TRUE

Value

List with three slots:

  • vif: data frame with the names of the selected variables and their respective VIF scores.

  • selected.variables: character vector with the names of the selected variables.

  • selected.variables.df: data frame with the selected variables.

Details

This function has two modes of operation:

  • 1. When the argument preference.order is NULL, the function removes on each iteration the variable with the highest VIF until all VIF values are lower than vif.threshold.

  • 2. When preference.order is provided, the variables are selected by giving them priority according to their order in preference.order. If there are variables not in preference.order, these are selected as in option 1. Once both groups of variables have been processed, all variables are put together and selected by giving priority to the ones in preference.order. This method preserves the variables desired by the user as much as possible.

Can be chained together with auto_cor() through pipes, see the examples below.

See also

Examples

if(interactive()){ #loading data data(plant_richness_df) #on a data frame out <- auto_vif(x = plant_richness_df[, 5:21]) #getting out the vif data frame out$vif #getting the names of the selected variables out$selected.variables #getting the data frame of selected variables out$selected.variables.df #on the result of auto_cor out <- auto_cor(x = plant_richness_df[, 5:21]) out <- auto_vif(x = out) #with pipes out <- plant_richness_df[, 5:21] %>% auto_cor() %>% auto_vif() }