R/cor_tables.R
cor_matrix.Rd
Calculates the correlation matrix between the numeric variables in a given dataframe and
includes descriptives (mean and standard deviation) - ready for creating a nice table with report_cor_table()
Adapted from http://www.sthda.com/english/wiki/elegant-correlation-table-using-xtable-r-package
Dataframe. Only numeric variables are included into correlation matrix.
A named character vector with new variable names or a tibble as provided by get_rename_tribbles()
for variables. If NULL, then the variables are not renamed. If names are provided, only the variables included here are retained.
This is most helpful when the results are passed to some print function, such as report_cor_table()
How should missing data be dealt with? Options are "pairwise" deletion, "listwise" deletion or "fiml" for full information maximum likelihood estimation of the correlation table. Note that if you use "fiml", this will also be applied to the estimation of means and standard deviations.
Confidence level to use for confidence intervals, defaults to .95
method="pearson" is the default value. The alternatives to be passed to cor are "spearman" and "kendall". These last two are much slower, particularly for big data sets.
What adjustment for multiple tests should be used? ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"). See p.adjust
for details about why to use "holm" rather than "bonferroni").
When using FIML estimation (with missing = "fiml"), significance tests and confidence intervals can be bootstrapped. If you want to do that, pass the number of desired bootstrap resamples (e.g., 5000) to this parameter, but beware that this can take a while.
Pass an integer to set the seed for bootstrapping and thus make this reproducible
A list including the correlation matrix, p-values, standard errors, t-values, pairwise number of observations, confidence intervals, descriptives and (if var_names was provided) a tibble with old and new variable names
By setting missing to "fiml", this function uses the lavaan package to estimate the correlations (and descriptives)
by using a full-information maximum likelihood algorithm. This estimates the covariances separately
for each pattern of missingness and then combines them based on the frequency of each pattern. This
will take longer than pairwise deletion, but should yield more precise estimates in the presence of
missing data. To date, FIML correlation matrices can be obtained with the psych::corFiml()
function, but that function does not report significance tests or confidence intervals, or with the
lavaan::lavCor()
function - this function also uses lavaan
for the estimation,
but facilitates bootstrapping and returns the results in a more accessible format.
For evidence on the utility of the FIML estimator, see Enders, C. K. (2001) The performance of the full information maximum likelihood estimator in multiple regression models with missing data