Learn R Programming

GimmeMyStats (version 1.0.0)

mcor_test: Multiple correlation test

Description

Calculates correlations between multiple variables.

Usage

mcor_test(
  x,
  y = NULL,
  estimate = TRUE,
  p.value = FALSE,
  method = "spearman",
  method_adjust = "BH"
)

Value

Depending on the values of estimate and p.value, one of the following:

estimate = TRUE, p.value = FALSE

A numeric matrix of correlation coefficients, with columns corresponding to variables in x and rows to variables in y.

estimate = FALSE, p.value = TRUE

A numeric matrix of adjusted p-values, with columns corresponding to variables in x and rows to variables in y.

estimate = TRUE, p.value = TRUE

A named list with two elements:

estimate

Numeric matrix of correlation coefficients.

p.value

Numeric matrix of adjusted p-values.

Arguments

x

Data frame containing numerical variables.

y

Data frame containing numerical variables. If NULL, correlations are calculated within x.

estimate

Logical specifying whether to return correlation coefficients.

p.value

Logical specifying whether to return adjusted p-values.

method

Character specifying the correlation method: pearson, kendall, or spearman.

method_adjust

Character specifying the p-value adjustment method.

Examples

Run this code
library(magrittr)
x0 <- runif(20)
x <- lapply(
    c(1, -1),
    function(i) sapply(seq(10), function(j) x0 * i + runif(10, max = 1))
) %>%
    Reduce(cbind, .) %>%
    set_colnames(paste("Variable", seq(20)))
y <- lapply(
    c(1, -1),
    function(i) sapply(seq(10), function(j) x0 * i + runif(10, max = 1))
) %>%
    Reduce(cbind, .) %>%
    set_colnames(paste("Variable", seq(20))) %>%
    .[, seq(5)]
mcor_test(x)
mcor_test(
    x,
    y,
    p.value = TRUE,
    method = "pearson",
    method_adjust = "bonferroni"
)

Run the code above in your browser using DataLab