| cor_matrix | R Documentation |
Computes a square matrix of pairwise correlations for a set of numeric and/or categorical predictors.
If df is already a correlation dataframe generated by cor_df()), the function transforms it into a correlation matrix. Otherwise, cor_df() is used internally to compute pairwise correlations before generating the matrix.
Supports parallel computation via future::plan() and optional progress reporting via progressr::handlers().
cor_matrix(df = NULL, predictors = NULL, quiet = FALSE, ...)
df |
(required; dataframe, tibble, or sf) A dataframe with predictors or the output of |
predictors |
(optional; character vector or NULL) Names of the
predictors in |
quiet |
(optional; logical) If FALSE, messages are printed. Default: FALSE. |
... |
(optional) Internal args (e.g. |
correlation matrix
Blas M. Benito, PhD
Other multicollinearity_assessment:
collinear_stats(),
cor_clusters(),
cor_cramer(),
cor_df(),
cor_stats(),
vif(),
vif_df(),
vif_stats()
data(vi_smol)
## 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)
predictors <- c(
"koppen_zone", #character
"soil_type", #factor
"topo_elevation", #numeric
"soil_temperature_mean" #numeric
)
#from dataframe with predictors
x <- cor_matrix(
df = vi_smol,
predictors = predictors
)
x
#from correlation dataframe
x <- cor_df(
df = vi,
predictors = predictors
) |>
cor_matrix()
x
## OPTIONAL: disable parallelization
#future::plan(future::sequential)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.