[ì°¸ê³ ] https://www.r-bloggers.com/the-ulimate-package-for-correlations-by-easystats/
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: coda
## Loading required package: Matrix
## ************
## Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
##
## Type BFManual() to open the manual.
## ************
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Parameter1 | Parameter2 | r | t | df | p | 95% CI | Method | n_Obs
## ---------------------------------------------------------------------------------------------
## Sepal.Length | Sepal.Width | -0.12 | -1.44 | 148 | 0.152 | [-0.27, 0.04] | Pearson | 150
## Sepal.Length | Petal.Length | 0.87 | 21.65 | 148 | < .001 | [ 0.83, 0.91] | Pearson | 150
## Sepal.Length | Petal.Width | 0.82 | 17.30 | 148 | < .001 | [ 0.76, 0.86] | Pearson | 150
## Sepal.Width | Petal.Length | -0.43 | -5.77 | 148 | < .001 | [-0.55, -0.29] | Pearson | 150
## Sepal.Width | Petal.Width | -0.37 | -4.79 | 148 | < .001 | [-0.50, -0.22] | Pearson | 150
## Petal.Length | Petal.Width | 0.96 | 43.39 | 148 | < .001 | [ 0.95, 0.97] | Pearson | 150
## Parameter | Petal.Width | Petal.Length | Sepal.Width
## -------------------------------------------------------
## Sepal.Length | 0.82*** | 0.87*** | -0.12
## Sepal.Width | -0.37*** | -0.43*** |
## Petal.Length | 0.96*** | |
## Parameter | Sepal.Length | Sepal.Width | Petal.Length | Petal.Width
## ----------------------------------------------------------------------
## Sepal.Length | 1.00*** | -0.12 | 0.87*** | 0.82***
## Sepal.Width | -0.12 | 1.00*** | -0.43*** | -0.37***
## Petal.Length | 0.87*** | -0.43*** | 1.00*** | 0.96***
## Petal.Width | 0.82*** | -0.37*** | 0.96*** | 1.00***
The function also supports stratified correlations, all within the tidyverse workflow!
iris %>%
select(Species, Petal.Width, Sepal.Length, Sepal.Width) %>%
group_by(Species) %>%
correlation()
## Group | Parameter1 | Parameter2 | r | t | df | p | 95% CI | Method | n_Obs
## ------------------------------------------------------------------------------------------------------
## setosa | Petal.Width | Sepal.Length | 0.28 | 2.01 | 48 | 0.101 | [ 0.00, 0.52] | Pearson | 50
## setosa | Petal.Width | Sepal.Width | 0.23 | 1.66 | 48 | 0.104 | [-0.05, 0.48] | Pearson | 50
## setosa | Sepal.Length | Sepal.Width | 0.74 | 7.68 | 48 | < .001 | [ 0.59, 0.85] | Pearson | 50
## versicolor | Petal.Width | Sepal.Length | 0.55 | 4.52 | 48 | < .001 | [ 0.32, 0.72] | Pearson | 50
## versicolor | Petal.Width | Sepal.Width | 0.66 | 6.15 | 48 | < .001 | [ 0.47, 0.80] | Pearson | 50
## versicolor | Sepal.Length | Sepal.Width | 0.53 | 4.28 | 48 | < .001 | [ 0.29, 0.70] | Pearson | 50
## virginica | Petal.Width | Sepal.Length | 0.28 | 2.03 | 48 | 0.048 | [ 0.00, 0.52] | Pearson | 50
## virginica | Petal.Width | Sepal.Width | 0.54 | 4.42 | 48 | < .001 | [ 0.31, 0.71] | Pearson | 50
## virginica | Sepal.Length | Sepal.Width | 0.46 | 3.56 | 48 | 0.002 | [ 0.20, 0.65] | Pearson | 50
It is very easy to switch to a Bayesian framework.
## Parameter1 | Parameter2 | rho | 89% CI | pd | % in ROPE | BF | Prior | n_Obs
## --------------------------------------------------------------------------------------------------------------
## Sepal.Length | Sepal.Width | -0.11 | [-0.24, 0.01] | 91.62% | 43.03% | 0.51 | Cauchy (0 +- 0.33) | 150
## Sepal.Length | Petal.Length | 0.86 | [ 0.83, 0.89] | 100% | 0% | > 999 | Cauchy (0 +- 0.33) | 150
## Sepal.Length | Petal.Width | 0.80 | [ 0.76, 0.85] | 100% | 0% | > 999 | Cauchy (0 +- 0.33) | 150
## Sepal.Width | Petal.Length | -0.41 | [-0.52, -0.31] | 100% | 0% | > 999 | Cauchy (0 +- 0.33) | 150
## Sepal.Width | Petal.Width | -0.35 | [-0.46, -0.23] | 100% | 0.07% | > 999 | Cauchy (0 +- 0.33) | 150
## Petal.Length | Petal.Width | 0.96 | [ 0.95, 0.97] | 100% | 0% | > 999 | Cauchy (0 +- 0.33) | 150
## Warning in biserialc(x[, j], y[, i], j, i): For x = 1 y = 1 x seems to be
## dichotomous, not continuous
## Warning in biserialc(x[, j], y[, i], j, i): For x = 1 y = 1 x seems to be
## dichotomous, not continuous
## Parameter1 | Parameter2 | r | t | df | p | 95% CI | Method | n_Obs
## --------------------------------------------------------------------------------------------------------------
## Sepal.Length | Sepal.Width | -0.12 | -1.44 | 148 | 0.304 | [-0.27, 0.04] | Pearson | 150
## Sepal.Length | Petal.Length | 0.87 | 21.65 | 148 | < .001 | [ 0.83, 0.91] | Pearson | 150
## Sepal.Length | Petal.Width | 0.82 | 17.30 | 148 | < .001 | [ 0.76, 0.86] | Pearson | 150
## Sepal.Length | Species.setosa | -0.93 | -29.97 | 148 | < .001 | [-0.95, -0.90] | Biserial | 150
## Sepal.Length | Species.versicolor | 0.10 | 1.25 | 148 | 0.304 | [-0.06, 0.26] | Biserial | 150
## Sepal.Length | Species.virginica | 0.82 | 17.66 | 148 | < .001 | [ 0.77, 0.87] | Biserial | 150
## Sepal.Width | Petal.Length | -0.43 | -5.77 | 148 | < .001 | [-0.55, -0.29] | Pearson | 150
## Sepal.Width | Petal.Width | -0.37 | -4.79 | 148 | < .001 | [-0.50, -0.22] | Pearson | 150
## Sepal.Width | Species.setosa | 0.78 | 15.09 | 148 | < .001 | [ 0.71, 0.84] | Biserial | 150
## Sepal.Width | Species.versicolor | -0.60 | -9.20 | 148 | < .001 | [-0.70, -0.49] | Biserial | 150
## Sepal.Width | Species.virginica | -0.18 | -2.16 | 148 | 0.130 | [-0.33, -0.02] | Biserial | 150
## Petal.Length | Petal.Width | 0.96 | 43.39 | 148 | < .001 | [ 0.95, 0.97] | Pearson | 150
## Petal.Length | Species.setosa | -1.00 | -Inf | 148 | < .001 | [-1.00, -1.00] | Biserial | 150
## Petal.Length | Species.versicolor | 0.26 | 3.27 | 148 | 0.007 | [ 0.10, 0.40] | Biserial | 150
## Petal.Length | Species.virginica | 0.93 | 31.09 | 148 | < .001 | [ 0.91, 0.95] | Biserial | 150
## Petal.Width | Species.setosa | -1.00 | -Inf | 148 | < .001 | [-1.00, -1.00] | Biserial | 150
## Petal.Width | Species.versicolor | 0.15 | 1.87 | 148 | 0.191 | [-0.01, 0.31] | Biserial | 150
## Petal.Width | Species.virginica | 0.99 | 112.56 | 148 | < .001 | [ 0.99, 1.00] | Biserial | 150
## Species.setosa | Species.versicolor | -0.88 | -22.35 | 148 | < .001 | [-0.91, -0.84] | Tetrachoric | 150
## Species.setosa | Species.virginica | -0.88 | -22.35 | 148 | < .001 | [-0.91, -0.84] | Tetrachoric | 150
## Species.versicolor | Species.virginica | -0.88 | -22.35 | 148 | < .001 | [-0.91, -0.84] | Tetrachoric | 150
It also supports partial correlations:
## Parameter | Petal.Width | Petal.Length | Sepal.Width
## -------------------------------------------------------
## Sepal.Length | -0.34*** | 0.72*** | 0.63***
## Sepal.Width | 0.35*** | -0.62*** |
## Petal.Length | 0.87*** | |
Such partial correlations can also be represented as Gaussian graphical models, an increasingly popular tool in psychology: