auto_vif {spatialRF} | R Documentation |
Multicollinearity reduction via Variance Inflation Factor
Description
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.
Usage
auto_vif(
x = NULL,
preference.order = NULL,
vif.threshold = 5,
verbose = TRUE
)
Arguments
x |
A data frame with predictors or the result of |
preference.order |
a character vector with columns names of x ordered by the user preference, Default: |
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 |
Details
This function has two modes of operation:
1. When the argument
preference.order
isNULL
, the function removes on each iteration the variable with the highest VIF until all VIF values are lower thanvif.threshold
.2. When
preference.order
is provided, the variables are selected by giving them priority according to their order inpreference.order
. If there are variables not inpreference.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 inpreference.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.
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.
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()
}