cor_test_multi: Test for Correlation Between Paired Samples for 2 or More...

View source: R/statistics-utils.R

cor_test_multiR Documentation

Test for Correlation Between Paired Samples for 2 or More Variables

Description

This function is a wrapper around stats::cor.test(). It implements the Pearson's correlation test that tests the null hypothesis that two or more paired samples of values are unrelated. This function can be applied to two or more numeric variables in the provided data.

Usage

cor_test_multi(
  .data,
  ...,
  .pvalues = FALSE,
  .ci = FALSE,
  .as_matrix = TRUE,
  .omit_redundancies = FALSE,
  .method = "pearson"
)

Arguments

.data

A data frame.

...

Variables for which the correlation coefficient should be returned. If no variable name is provided, correlations will be returned for all numeric variables in .data.

.pvalues

logical If FALSE (default), p-values will be omitted from the output. If TRUE, p-values will be included in the output.

.ci

logical If FALSE (default), 95% confidence interval bounds will be omitted from the output. If TRUE, 95% confidence interval bounds will be included in the output.

.as_matrix

logical If TRUE (default), results will be return as matrix. If TRUE, results will be returned as tibble.

.omit_redundancies

logical If FALSE (default), all n^2 correlations will be include in the output. If TRUE, only unique correlations will be returned (x ~ y but not y ~ x) and correlation of a variable with itself will be omitted.

.method

A character string indicating which correlation coefficient is to be used: "pearson", "kendall", or "spearman". Default method is "pearson".

Value

By default a matrix with correlation coefficients. Output format and included statistics can be changed in the argument settings.

Examples

# Calculate the correlations between all numeric variables in the `faithfulfaces` data.
cor_test_multi(faithfulfaces)
# Calculate the correlations between the 1st, 2nd and 4th variable.
cor_test_multi(faithfulfaces, c(1,2,4))
# Calculate the correlations between `sex_dimorph`, `attractive`, and `trustworthy`.
cor_test_multi(faithfulfaces, sex_dimorph, attractive, trustworthy)
# Calculate all correlations and return p-values and 95% confidence intervals.
cor_test_multi(faithfulfaces, .pvalues = TRUE, .ci = TRUE)
# Calculate all correlations with p-values and 95% confidence intervals and 
# return results as table with only unique pairs of the off-diagonal correlations.
cor_test_multi(faithfulfaces, .pvalues = TRUE, .ci = TRUE, .as_matrix = FALSE, 
.omit_redundancies = TRUE)

mark-andrews/psyntur documentation built on Nov. 18, 2024, 7:17 a.m.