paper/paper.md

title: 'Methods and Algorithms for Correlation Analysis in R' tags: - R - Correlation - Easystats authors: - affiliation: 1 name: Dominique Makowski orcid: 0000-0001-5375-9967 - affiliation: 2 name: Mattan S. Ben-Shachar orcid: 0000-0002-4287-4801 - affiliation: 3 name: Indrajeet Patil orcid: 0000-0003-1995-6531 - affiliation: 4 name: Daniel Lüdecke orcid: 0000-0002-8895-3206 affiliations: - index: 1 name: Nanyang Technological University, Singapore - index: 2 name: Ben-Gurion University of the Negev, Israel - index: 3 name: Max Planck Institute for Human Development, Germany - index: 4 name: University Medical Center Hamburg-Eppendorf, Germany date: "22 March 2020" bibliography: paper.bib csl: apa.csl output: pdf_document

Introduction

Correlations tests are arguably one of the most commonly used statistical procedures, and are used as a basis in many applications such as exploratory data analysis, structural modelling, data engineering etc. In this context, we present correlation, a toolbox for the R language [@Rteam] and part of the easystats collection, focused on correlation analysis. Its goal is to be lightweight, easy to use, and allows for the computation of many different kinds of correlations, such as:

$$r_{xy} = \frac{cov(x,y)}{SD_x \times SD_y}$$

$$r_{s_{xy}} = \frac{cov(rank_x, rank_y)}{SD(rank_x) \times SD(rank_y)}$$

$$\tau_{xy} = \frac{2}{n(n-1)}\sum_{i<j}^{}sign(x_i - x_j) \times sign(y_i - y_j)$$

$$r_{xy.z} = r_{e_{x.z},e_{y.z}}$$

These methods allow for different ways of quantifying the link between two variables (see Figure 1).

Illustration of the different correlation estimates (a measure of association, represent by the height of the bars) obtained via different methods for the same data (the scatter plot).

Design

It relies on one main function, correlation(), which outputs a dataframe containing each pairwise correlation per row. This long format is convenient for further data analysis, but not as much to get a summary, which is usually obtained via a correlation matrix. To address this, we added standard methods, such as summary() and as.matrix(), to automatically transform the long output to a matrix. Moreover, correlation also includes plotting capabilities via the see package [@ludecke2019see].

An overview of the features is available on the GitHub page (https://github.com/easystats/correlation). The typical core workflow is as follows:

\footnotesize

results <- correlation(iris)
results
# Parameter1   |   Parameter2 |     r |         95% CI |     t |  df |      p |  Method | n_Obs
# ---------------------------------------------------------------------------------------------
# Sepal.Length |  Sepal.Width | -0.12 | [-0.27,  0.04] | -1.44 | 148 | 0.152  | Pearson |   150
# Sepal.Length | Petal.Length |  0.87 | [ 0.83,  0.91] | 21.65 | 148 | < .001 | Pearson |   150
# Sepal.Length |  Petal.Width |  0.82 | [ 0.76,  0.86] | 17.30 | 148 | < .001 | Pearson |   150
# Sepal.Width  | Petal.Length | -0.43 | [-0.55, -0.29] | -5.77 | 148 | < .001 | Pearson |   150
# Sepal.Width  |  Petal.Width | -0.37 | [-0.50, -0.22] | -4.79 | 148 | < .001 | Pearson |   150
# Petal.Length |  Petal.Width |  0.96 | [ 0.95,  0.97] | 43.39 | 148 | < .001 | Pearson |   150

\normalsize

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

\small

summary(results)
# 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*** |              |

\normalsize

Availability

The correlation package can be downloaded and installed from CRAN 1. It is licensed under the GNU General Public License (v3.0), with all its source code stored at GitHub 2, and with a corresponding issue tracker 2 for bug reporting and feature enhancements. In the spirit of honest and open science, we encourage requests/tips for fixes, feature updates, as well as general questions and concerns via direct interaction with contributors and developers.

Acknowledgments

correlation is part of the easystats ecosystem [relying on insight; @ludecke2019insight and bayestestR; @makowski2019bayestestr], a collaborative project created to facilitate the usage of R. Thus, we would like to thank the council of masters of easystats, all other padawan contributors, as well as the users.

References



easystats/correlation documentation built on April 12, 2025, 10:53 p.m.