All Projects â†’ easystats â†’ Correlation

easystats / Correlation

Licence: gpl-3.0
đź”— Methods for Correlation Analysis

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Correlation

Mathnet Numerics
Math.NET Numerics
Stars: âś­ 2,688 (+1300%)
Mutual labels:  matrix, regression
ara
Agile Regression Analyzer
Stars: âś­ 74 (-61.46%)
Mutual labels:  test, regression
Peroxide
Rust numeric library with R, MATLAB & Python syntax
Stars: âś­ 191 (-0.52%)
Mutual labels:  matrix, regression
BAS
BAS R package https://merliseclyde.github.io/BAS/
Stars: âś­ 36 (-81.25%)
Mutual labels:  regression, bayesian
Owl
Owl - OCaml Scientific and Engineering Computing @ http://ocaml.xyz
Stars: âś­ 919 (+378.65%)
Mutual labels:  matrix, regression
Gpstuff
GPstuff - Gaussian process models for Bayesian analysis
Stars: âś­ 106 (-44.79%)
Mutual labels:  bayesian, regression
combining3Dmorphablemodels
Project Page of Combining 3D Morphable Models: A Large scale Face-and-Head Model - [CVPR 2019]
Stars: âś­ 80 (-58.33%)
Mutual labels:  matrix, regression
AI-cheat-sheet
cheat sheet for Artificial Intelligence
Stars: âś­ 20 (-89.58%)
Mutual labels:  regression, bayesian
Cranium
🤖 A portable, header-only, artificial neural network library written in C99
Stars: âś­ 501 (+160.94%)
Mutual labels:  matrix, regression
Yannl
Yet another neural network library
Stars: âś­ 37 (-80.73%)
Mutual labels:  matrix, regression
Math Php
Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra
Stars: âś­ 2,009 (+946.35%)
Mutual labels:  matrix, regression
Deep Time Series Prediction
Seq2Seq, Bert, Transformer, WaveNet for time series prediction.
Stars: âś­ 183 (-4.69%)
Mutual labels:  regression
Mocktopus
Mocking framework for Rust
Stars: âś­ 179 (-6.77%)
Mutual labels:  test
Ugm
Ubpa Graphics Mathematics
Stars: âś­ 178 (-7.29%)
Mutual labels:  matrix
Preact Render Spy
Render preact components with access to the produced virtual dom for testing.
Stars: âś­ 178 (-7.29%)
Mutual labels:  test
Hitchhiker
a Restful Api test tool
Stars: âś­ 2,175 (+1032.81%)
Mutual labels:  test
Decomposed
CATransform3D manipulation made easy.
Stars: âś­ 184 (-4.17%)
Mutual labels:  matrix
Vscode Java Test
Run and debug Java test cases in Visual Studio Code.
Stars: âś­ 177 (-7.81%)
Mutual labels:  test
Testen
✔️ Run tests for multiple versions of Node.js in local env.
Stars: âś­ 176 (-8.33%)
Mutual labels:  test
Phpsci Carray
PHP library for scientific computing powered by C
Stars: âś­ 176 (-8.33%)
Mutual labels:  matrix

correlation

DOI downloads total

correlation is an easystats package focused on correlation analysis. It’s lightweight, easy to use, and allows for the computation of many different kinds of correlations, such as partial correlations, Bayesian correlations, multilevel correlations, polychoric correlations, biweight, percentage bend or Sheperd’s Pi correlations (types of robust correlation), distance correlation (a type of non-linear correlation) and more, also allowing for combinations between them (for instance, Bayesian partial multilevel correlation).

You can reference the package and its documentation as follows:

  • Makowski, D., Ben-Shachar, M. S., Patil, I., & LĂĽdecke, D. (2019). Methods and Algorithms for Correlation Analysis in R. Journal of Open Source Software, 5(51), 2306. 10.21105/joss.02306

Installation

CRAN Build Status codecov

Run the following to install the stable release of correlation from CRAN:

install.packages("correlation")

Or this one to install the latest development version:

install.packages("remotes")
remotes::install_github("easystats/correlation")

Documentation

Documentation Blog Features

Click on the buttons above to access the package documentation and the easystats blog, and check-out these vignettes:

Features

The correlation package can compute many different types of correlation, including:

  • [x] Pearson’s correlation
  • [x] Spearman’s rank correlation
  • [x] Kendall’s rank correlation
  • [x] Biweight midcorrelation
  • [x] Distance correlation
  • [x] Percentage bend correlation
  • [x] Shepherd’s Pi correlation
  • [x] Blomqvist’s coefficient
  • [x] Hoeffding’s D
  • [x] Gamma correlation
  • [x] Gaussian rank correlation
  • [x] Point-Biserial and biserial correlation
  • [x] Winsorized correlation
  • [x] Polychoric correlation
  • [x] Tetrachoric correlation
  • [x] Multilevel correlation

An overview and description of these correlations types is available here. Moreover, many of these correlation types are available as partial or within a Bayesian framework.

Examples

The main function is correlation(), which builds on top of cor_test() and comes with a number of possible options.

Correlation details and matrix

results <- correlation(iris)
results
## # Correlation table (pearson-method)
## 
## Parameter1   |   Parameter2 |     r |         95% CI | t(148) |         p
## -------------------------------------------------------------------------
## Sepal.Length |  Sepal.Width | -0.12 | [-0.27,  0.04] |  -1.44 | 0.152    
## Sepal.Length | Petal.Length |  0.87 | [ 0.83,  0.91] |  21.65 | < .001***
## Sepal.Length |  Petal.Width |  0.82 | [ 0.76,  0.86] |  17.30 | < .001***
## Sepal.Width  | Petal.Length | -0.43 | [-0.55, -0.29] |  -5.77 | < .001***
## Sepal.Width  |  Petal.Width | -0.37 | [-0.50, -0.22] |  -4.79 | < .001***
## Petal.Length |  Petal.Width |  0.96 | [ 0.95,  0.97] |  43.39 | < .001***
## 
## p-value adjustment method: Holm (1979)
## Observations: 150

The output is not a square matrix, but a (tidy) dataframe with all correlations tests per row. One can also obtain a matrix using:

summary(results)
## # Correlation Matrix (pearson-method)
## 
## 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*** |              |            
## 
## p-value adjustment method: Holm (1979)

Note that one can also obtain the full, square and redundant matrix using:

summary(results, redundant=TRUE)
## # Correlation Matrix (pearson-method)
## 
## 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***
## 
## p-value adjustment method: Holm (1979)
library(dplyr)
library(see)

results %>% 
  summary(redundant=TRUE) %>% 
  plot()

Grouped dataframes

The function also supports stratified correlations, all within the tidyverse workflow!

iris %>% 
  select(Species, Sepal.Length, Sepal.Width, Petal.Width) %>% 
  group_by(Species) %>% 
  correlation()
## # Correlation table (pearson-method)
## 
## Group      |   Parameter1 |  Parameter2 |    r |        95% CI | t(48) |         p
## ----------------------------------------------------------------------------------
## setosa     | Sepal.Length | Sepal.Width | 0.74 | [ 0.59, 0.85] |  7.68 | < .001***
## setosa     | Sepal.Length | Petal.Width | 0.28 | [ 0.00, 0.52] |  2.01 | 0.101    
## setosa     |  Sepal.Width | Petal.Width | 0.23 | [-0.05, 0.48] |  1.66 | 0.104    
## versicolor | Sepal.Length | Sepal.Width | 0.53 | [ 0.29, 0.70] |  4.28 | < .001***
## versicolor | Sepal.Length | Petal.Width | 0.55 | [ 0.32, 0.72] |  4.52 | < .001***
## versicolor |  Sepal.Width | Petal.Width | 0.66 | [ 0.47, 0.80] |  6.15 | < .001***
## virginica  | Sepal.Length | Sepal.Width | 0.46 | [ 0.20, 0.65] |  3.56 | 0.002**  
## virginica  | Sepal.Length | Petal.Width | 0.28 | [ 0.00, 0.52] |  2.03 | 0.048*   
## virginica  |  Sepal.Width | Petal.Width | 0.54 | [ 0.31, 0.71] |  4.42 | < .001***
## 
## p-value adjustment method: Holm (1979)
## Observations: 50

Bayesian Correlations

It is very easy to switch to a Bayesian framework.

correlation(iris, bayesian = TRUE)
## # Correlation table (pearson-method)
## 
## Parameter1   |   Parameter2 |   rho |         95% CI |      pd | % in ROPE |        BF |         Prior
## ------------------------------------------------------------------------------------------------------
## Sepal.Length |  Sepal.Width | -0.11 | [-0.24,  0.01] |  92.38% |    42.83% |     0.509 | Beta (3 +- 3)
## Sepal.Length | Petal.Length |  0.86 | [ 0.82,  0.89] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
## Sepal.Length |  Petal.Width |  0.80 | [ 0.76,  0.85] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
## Sepal.Width  | Petal.Length | -0.41 | [-0.52, -0.31] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
## Sepal.Width  |  Petal.Width | -0.35 | [-0.46, -0.24] | 100%*** |     0.12% | > 1000*** | Beta (3 +- 3)
## Petal.Length |  Petal.Width |  0.96 | [ 0.95,  0.97] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
## 
## Observations: 150

Tetrachoric, Polychoric, Biserial, Biweight…

The correlation package also supports different types of methods, which can deal with correlations between factors!

correlation(iris, include_factors = TRUE, method = "auto")
## # Correlation table (auto-method)
## 
## Parameter1         |         Parameter2 |     r |         95% CI | t(148) |         p
## -------------------------------------------------------------------------------------
## Sepal.Length       |        Sepal.Width | -0.12 | [-0.27,  0.04] |  -1.44 | 0.452    
## Sepal.Length       |       Petal.Length |  0.87 | [ 0.83,  0.91] |  21.65 | < .001***
## Sepal.Length       |        Petal.Width |  0.82 | [ 0.76,  0.86] |  17.30 | < .001***
## Sepal.Length       |     Species.setosa | -0.72 | [-0.79, -0.63] | -12.53 | < .001***
## Sepal.Length       | Species.versicolor |  0.08 | [-0.08,  0.24] |   0.97 | 0.452    
## Sepal.Length       |  Species.virginica |  0.64 | [ 0.53,  0.72] |  10.08 | < .001***
## Sepal.Width        |       Petal.Length | -0.43 | [-0.55, -0.29] |  -5.77 | < .001***
## Sepal.Width        |        Petal.Width | -0.37 | [-0.50, -0.22] |  -4.79 | < .001***
## Sepal.Width        |     Species.setosa |  0.60 | [ 0.49,  0.70] |   9.20 | < .001***
## Sepal.Width        | Species.versicolor | -0.47 | [-0.58, -0.33] |  -6.44 | < .001***
## Sepal.Width        |  Species.virginica | -0.14 | [-0.29,  0.03] |  -1.67 | 0.392    
## Petal.Length       |        Petal.Width |  0.96 | [ 0.95,  0.97] |  43.39 | < .001***
## Petal.Length       |     Species.setosa | -0.92 | [-0.94, -0.89] | -29.13 | < .001***
## Petal.Length       | Species.versicolor |  0.20 | [ 0.04,  0.35] |   2.51 | 0.066    
## Petal.Length       |  Species.virginica |  0.72 | [ 0.63,  0.79] |  12.66 | < .001***
## Petal.Width        |     Species.setosa | -0.89 | [-0.92, -0.85] | -23.41 | < .001***
## Petal.Width        | Species.versicolor |  0.12 | [-0.04,  0.27] |   1.44 | 0.452    
## Petal.Width        |  Species.virginica |  0.77 | [ 0.69,  0.83] |  14.66 | < .001***
## Species.setosa     | Species.versicolor | -0.88 | [-0.91, -0.84] | -22.43 | < .001***
## Species.setosa     |  Species.virginica | -0.88 | [-0.91, -0.84] | -22.43 | < .001***
## Species.versicolor |  Species.virginica | -0.88 | [-0.91, -0.84] | -22.43 | < .001***
## 
## p-value adjustment method: Holm (1979)
## Observations: 150

Partial Correlations

It also supports partial correlations (as well as Bayesian partial correlations).

iris %>% 
  correlation(partial = TRUE) %>% 
  summary()
## # Correlation Matrix (pearson-method)
## 
## 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*** |              |            
## 
## p-value adjustment method: Holm (1979)

Gaussian Graphical Models (GGMs)

Such partial correlations can also be represented as Gaussian Graphical Models (GGM), an increasingly popular tool in psychology. A GGM traditionally include a set of variables depicted as circles (“nodes”), and a set of lines that visualize relationships between them, which thickness represents the strength of association (see Bhushan et al., 2019).

library(see) # for plotting
library(ggraph) # needs to be loaded

mtcars %>% 
  correlation(partial = TRUE) %>% 
  plot()

Multilevel Correlations

It also provide some cutting-edge methods, such as Multilevel (partial) correlations. These are are partial correlations based on linear mixed models that include the factors as random effects. They can be see as correlations adjusted for some group (hierarchical) variability.

iris %>% 
  correlation(partial = TRUE, multilevel = TRUE) %>% 
  summary()
## # Correlation Matrix (pearson-method)
## 
## Parameter    | Petal.Width | Petal.Length | Sepal.Width
## -------------------------------------------------------
## Sepal.Length |      -0.17* |      0.71*** |     0.43***
## Sepal.Width  |     0.39*** |       -0.18* |            
## Petal.Length |     0.38*** |              |            
## 
## p-value adjustment method: Holm (1979)

However, if the partial argument is set to FALSE, it will try to convert the partial coefficient into regular ones.These can be converted back to full correlations:

iris %>% 
  correlation(partial = FALSE, multilevel = TRUE) %>% 
  summary()
## Parameter    | Petal.Width | Petal.Length | Sepal.Width
## -------------------------------------------------------
## Sepal.Length |     0.36*** |      0.76*** |     0.53***
## Sepal.Width  |     0.47*** |      0.38*** |            
## Petal.Length |     0.48*** |              |
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].