compare_cor: Compare correlations

View source: R/compare_cor.R

compare_corR Documentation

Compare correlations

Description

This function is a wrapper around psych::r.test.

Usage

compare_cor(data, r1, r2, data2 = NULL, by = NULL, ci = 0.95)

Arguments

data

A data frame

r1, r2

Names of variable for the first and second correlations

data2

Where to look for the r2 columns (if not provided, looked for on data).

by

Name of column to split data by. The column must have only 2 unique values. If provided, the correlation between r1 is compared between the two groups.

ci

Confidence level for correlations.

Details

  • If data2 is provided, the correlation between r1 (in data) and r2 (in data2) is compared.

    • If r2 not provided, the correlation between r1 (in data) and r1 (in data2) is compared

  • If by is provided r1 (in data) is compared between the 2 groups.

  • Else, a test for the difference of two dependent correlations is conducted.

Value

A list of two data frames:

  1. The two correlations + their CIs

  2. The test results

Examples

# Test dependent correlations ------------------
## different variables
compare_cor(mtcars, r1 = c("mpg", "hp"), r2 = c("drat", "am"))

## 1 shared variable
compare_cor(mtcars, r1 = c("mpg", "hp"), r2 = c("mpg", "am"))



# Test independent correlations -----------------
## Different data sets
compare_cor(
  data = mtcars, r1 = c("mpg", "hp"),
  data2 = iris, r2 = c("Sepal.Length", "Sepal.Width")
)

## Groups
compare_cor(mtcars, r1 = c("mpg", "hp"), by = "am")


mattansb/MSBMisc documentation built on March 22, 2023, 6:02 p.m.