{"id":13586775,"url":"https://github.com/easystats/correlation","last_synced_at":"2025-05-14T17:03:53.572Z","repository":{"id":39600313,"uuid":"171659421","full_name":"easystats/correlation","owner":"easystats","description":":link: Methods for Correlation Analysis","archived":false,"fork":false,"pushed_at":"2025-04-08T16:36:54.000Z","size":166316,"stargazers_count":440,"open_issues_count":64,"forks_count":57,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-04-13T03:59:44.370Z","etag":null,"topics":["bayesian","bayesian-correlations","biserial","cor","correlation","correlation-analysis","correlations","easystats","gamma","gaussian-graphical-models","hacktoberfest","matrix","multilevel-correlations","outliers","partial","partial-correlations","r","regression","robust","spearman"],"latest_commit_sha":null,"homepage":"https://easystats.github.io/correlation/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/easystats.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"easystats"}},"created_at":"2019-02-20T11:19:54.000Z","updated_at":"2025-04-06T12:55:18.000Z","dependencies_parsed_at":"2023-02-18T19:31:24.417Z","dependency_job_id":"6e5dfabb-2679-44fc-818b-b517a13ef8ba","html_url":"https://github.com/easystats/correlation","commit_stats":{"total_commits":637,"total_committers":13,"mean_commits":49.0,"dds":0.6562009419152277,"last_synced_commit":"fced7856bc287135b17b752150777db11a8b8cf0"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easystats%2Fcorrelation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easystats%2Fcorrelation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easystats%2Fcorrelation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easystats%2Fcorrelation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easystats","download_url":"https://codeload.github.com/easystats/correlation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661706,"owners_count":21141450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","bayesian-correlations","biserial","cor","correlation","correlation-analysis","correlations","easystats","gamma","gaussian-graphical-models","hacktoberfest","matrix","multilevel-correlations","outliers","partial","partial-correlations","r","regression","robust","spearman"],"created_at":"2024-08-01T15:05:48.197Z","updated_at":"2025-04-13T03:59:52.984Z","avatar_url":"https://github.com/easystats.png","language":"R","readme":"---\noutput: github_document\n---\n\n# correlation \u003cimg src='man/figures/logo.png' align=\"right\" height=\"139\" /\u003e\n\n```{r README-1, warning=FALSE, message=FALSE, echo=FALSE}\nlibrary(ggplot2)\nlibrary(poorman)\nlibrary(correlation)\n\noptions(digits = 2)\n\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  dpi = 300,\n  message = FALSE,\n  warning = FALSE,\n  fig.path = \"man/figures/\"\n)\n```\n\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.02306/status.svg)](https://doi.org/10.21105/joss.02306)  [![downloads](https://cranlogs.r-pkg.org/badges/correlation)](https://cran.r-project.org/package=correlation)\n[![total](https://cranlogs.r-pkg.org/badges/grand-total/correlation)](https://cranlogs.r-pkg.org/)\n\n`correlation` is an [**easystats**](https://github.com/easystats/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*).\n\n# Citation\n\nYou can cite the package as follows:\n\nMakowski, D., Ben-Shachar, M. S., Patil, I., \\\u0026 Lüdecke, D. (2020). Methods and algorithms for correlation analysis in R. _Journal of Open Source Software_,\n*5*(51), 2306. https://doi.org/10.21105/joss.02306\n\nMakowski, D., Wiernik, B. M., Patil, I., Lüdecke, D., \\\u0026 Ben-Shachar, M. S. (2022). *correlation*: Methods for correlation analysis [R package]. https://CRAN.R-project.org/package=correlation (Original work published 2020)\n\n# Installation\n\n[![CRAN](https://www.r-pkg.org/badges/version/correlation)](https://cran.r-project.org/package=correlation) [![correlation status badge](https://easystats.r-universe.dev/badges/correlation)](https://easystats.r-universe.dev) [![codecov](https://codecov.io/gh/easystats/correlation/branch/main/graph/badge.svg)](https://app.codecov.io/gh/easystats/correlation)\n\nThe *correlation* package is available on CRAN, while its latest development version is available on R-universe (from _rOpenSci_).\n\nType | Source | Command\n---|---|---\nRelease | CRAN | `install.packages(\"correlation\")`\nDevelopment | R-universe | `install.packages(\"correlation\", repos = \"https://easystats.r-universe.dev\")`\n\nOnce you have downloaded the package, you can then load it using:\n\n```{r, eval=FALSE}\nlibrary(\"correlation\")\n```\n\n\u003e **Tip**\n\u003e\n\u003e Instead of `library(bayestestR)`, use `library(easystats)`.\n\u003e This will make all features of the  easystats-ecosystem available.\n\u003e\n\u003e To stay updated, use `easystats::install_latest()`.\n\n# Documentation\n\n[![Documentation](https://img.shields.io/badge/documentation-correlation-orange.svg?colorB=E91E63)](https://easystats.github.io/correlation/)\n[![Blog](https://img.shields.io/badge/blog-easystats-orange.svg?colorB=FF9800)](https://easystats.github.io/blog/posts/)\n[![Features](https://img.shields.io/badge/features-correlation-orange.svg?colorB=2196F3)](https://easystats.github.io/correlation/reference/index.html)\n\n\nCheck out package [website](https://easystats.github.io/correlation/) for documentation.\n\n# Features\n\nThe *correlation* package can compute many different types of correlation,\nincluding:\n\n✅ **Pearson's correlation**\u003cbr\u003e\n✅ **Spearman's rank correlation**\u003cbr\u003e\n✅ **Kendall's rank correlation**\u003cbr\u003e\n✅ **Biweight midcorrelation**\u003cbr\u003e\n✅ **Distance correlation**\u003cbr\u003e\n✅ **Percentage bend correlation**\u003cbr\u003e\n✅ **Shepherd's Pi correlation**\u003cbr\u003e\n✅ **Blomqvist’s coefficient**\u003cbr\u003e\n✅ **Hoeffding’s D**\u003cbr\u003e\n✅ **Gamma correlation**\u003cbr\u003e\n✅ **Gaussian rank correlation**\u003cbr\u003e\n✅ **Point-Biserial and biserial correlation**\u003cbr\u003e\n✅ **Winsorized correlation**\u003cbr\u003e\n✅ **Polychoric correlation**\u003cbr\u003e\n✅ **Tetrachoric correlation**\u003cbr\u003e\n✅ **Multilevel correlation**\u003cbr\u003e\n\nAn overview and description of these correlations types is [**available here**](https://easystats.github.io/correlation/articles/types.html). Moreover,\nmany of these correlation types are available as **partial** or within a\n**Bayesian** framework.\n\n# Examples\n\nThe main function is [`correlation()`](https://easystats.github.io/correlation/reference/correlation.html), which builds on top of [`cor_test()`](https://easystats.github.io/correlation/reference/cor_test.html) and comes with a number of possible options.\n\n## Correlation details and matrix\n\n```{r README-4}\nresults \u003c- correlation(iris)\nresults\n```\n\nThe output is not a square matrix, but a **(tidy) dataframe with all correlations tests per row**. One can also obtain a **matrix** using:\n\n```{r README-5}\nsummary(results)\n```\n\nNote that one can also obtain the full, **square** and redundant matrix using:\n\n```{r README-6}\nsummary(results, redundant = TRUE)\n```\n\n\n```{r README-7}\nlibrary(see)\n\nresults %\u003e%\n  summary(redundant = TRUE) %\u003e%\n  plot()\n```\n\n## Correlation tests\n\nThe `cor_test()` function, for pairwise correlations, is also very convenient for making quick scatter plots.\n\n```{r README-corr}\nplot(cor_test(iris, \"Sepal.Width\", \"Sepal.Length\"))\n```\n\n## Grouped dataframes\n\nThe `correlation()` function also supports **stratified correlations**, all within the\n*tidyverse* workflow!\n\n```{r README-8}\niris %\u003e%\n  select(Species, Sepal.Length, Sepal.Width, Petal.Width) %\u003e%\n  group_by(Species) %\u003e%\n  correlation()\n```\n\n## Bayesian Correlations\n\nIt is very easy to switch to a **Bayesian framework**.\n\n```{r README-9}\ncorrelation(iris, bayesian = TRUE)\n```\n\n## Tetrachoric, Polychoric, Biserial, Biweight...\n\nThe `correlation` package also supports different types of methods, which can\ndeal with correlations **between factors**!\n\n```{r README-10}\ncorrelation(iris, include_factors = TRUE, method = \"auto\")\n```\n\n## Partial Correlations\n\nIt also supports **partial correlations** (as well as Bayesian partial correlations).\n\n```{r README-11}\niris %\u003e%\n  correlation(partial = TRUE) %\u003e%\n  summary()\n```\n\n## Gaussian Graphical Models (GGMs)\n\nSuch partial correlations can also be represented as **Gaussian Graphical\nModels** (GGM), an increasingly popular tool in psychology. A GGM traditionally\ninclude a set of variables depicted as circles (\"nodes\"), and a set of lines\nthat visualize relationships between them, which thickness represents the\nstrength of association (see [Bhushan et al., 2019](https://www.frontiersin.org/articles/10.3389/fpsyg.2019.01050/full)).\n\n```{r README-12}\nlibrary(see) # for plotting\nlibrary(ggraph) # needs to be loaded\n\nplot(correlation(mtcars, partial = TRUE)) +\n  scale_edge_color_continuous(low = \"#000004FF\", high = \"#FCFDBFFF\")\n```\n\n## Multilevel Correlations\n\nIt also provide some cutting-edge methods, such as Multilevel (partial)\ncorrelations. These are are partial correlations based on linear mixed-effects\nmodels that include the factors as **random effects**. They can be see as\ncorrelations *adjusted* for some group (*hierarchical*) variability.\n\n```{r README-13}\niris %\u003e%\n  correlation(partial = TRUE, multilevel = TRUE) %\u003e%\n  summary()\n```\n\nHowever, if the `partial` argument is set to `FALSE`, it will try to convert the\npartial coefficient into regular ones.These can be **converted back** to full\ncorrelations:\n\n```{r README-14}\niris %\u003e%\n  correlation(partial = FALSE, multilevel = TRUE) %\u003e%\n  summary()\n```\n\n# Contributing and Support\n\nIn case you want to file an issue or contribute in another way to the package, please follow [this guide](https://easystats.github.io/correlation/CONTRIBUTING.html). For questions about the functionality, you may either contact us via email or also file an issue.\n\n# Code of Conduct\n\nPlease note that this project is released with a \n[Contributor Code of Conduct](https://easystats.github.io/correlation/CODE_OF_CONDUCT.html). By participating in this project you agree to abide by its terms.\n","funding_links":["https://github.com/sponsors/easystats"],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasystats%2Fcorrelation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasystats%2Fcorrelation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasystats%2Fcorrelation/lists"}