compare_cor | R Documentation |
This function is a wrapper around psych::r.test.
compare_cor(data, r1, r2, data2 = NULL, by = NULL, ci = 0.95)
data |
A data frame |
r1, r2 |
Names of variable for the first and second correlations |
data2 |
Where to look for the |
by |
Name of column to split |
ci |
Confidence level for correlations. |
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.
A list of two data frames:
The two correlations + their CIs
The test results
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.