Skip to main content

pymccorrelation

A tool to calculate correlation coefficients for data, using bootstrapping and/or perturbation to estimate the uncertainties on the correlation coefficient. This was initially a python implementation of the Curran (2014) method for calculating uncertainties on Spearman's Rank Correlation Coefficient, but has since been expanded. Curran's original C implementation is MCSpearman (ASCL entry).

Currently the following correlation coefficients can be calculated (with bootstrapping and/or perturbation):

Kendall's tau can also calculated when some of the data are left/right censored, following the method described by Isobe+1986.

Requirements

  • python3
  • scipy
  • numpy

Installation

pymccorrelation is available via PyPi and can be installed with:

pip install pymccorrelation

Usage

pymccorrelation exports a single function to the user (also called pymccorrelation).

from pymccorrelation import pymccorrelation

[... load your data ...]

The correlation coefficient can be one of pearsonr, spearmanr, or kendallt.

For example, to compute the Pearson's r for a sample, using 1000 bootstrapping iterations to estimate the uncertainties:

res = pymccorrelation(data['x'], data['y]',
                      coeff='pearsonr',
                      Nboot=1000)

The output, res is a tuple of length 2, and the two elements are:

  • numpy array with the correlation coefficient (Pearson's r, in this case) percentiles (by default 16%, 50%, and 84%)
  • numpy array with the p-value percentiles (by default 16%, 50%, and 84%)

The percentile ranges can be adjusted using the percentiles keyword argument.

Additionally, if the full posterior distribution is desired, that can be obtained by setting the return_dist keyword argument to True. In that case, res becomes a tuple of length four:

  • numpy array with the correlation coefficient (Pearson's r, in this case) percentiles (by default 16%, 50%, and 84%)
  • numpy array with the p-value percentiles (by default 16%, 50%, and 84%)
  • numpy array with full set of correlation coefficient values from the bootstrapping
  • numpy array with the full set of p-values computed from the bootstrapping

Please see the docstring for the full set of arguments and information including measurement uncertainties (necessary for point perturbation) and for marking censored data.

Citing

If you use this script as part of your research, I encourage you to cite the following papers:

  • Curran 2014: Describes the technique and application to Spearman's rank correlation coefficient
  • Privon+ 2020: First use of this software, as pymcspearman.

Please also cite scipy and numpy.

If your work uses Kendall's tau, with censored data please also cite:

  • Isobe+ 1986: Censoring of data when computing Kendall's rank correlation coefficient.

Release files for pymccorrelation 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymccorrelation 0.2.2
File Size Uploaded
pymccorrelation-0.2.2.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymccorrelation 0.2.2
File Interpreter ABI Platform
pymccorrelation-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 39.9 kB

Release files / pymccorrelation-0.2.2.tar.gz

Download URL pymccorrelation-0.2.2.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d73d73b103324b53ab46f38b25c6ca4b81092d205ca042ace6673481dd731ed3
BLAKE2b-256 checksum
How to use checksums
b69abef05483d0def21f536313899dd2a82e3ffd8195aeb502dabb90cd3d8c95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / pymccorrelation-0.2.2-py3-none-any.whl

Download URL pymccorrelation-0.2.2-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d95b9c7c5cc4f82f065572f57db11c89e510431433c28b73c18e3648de534a0
BLAKE2b-256 checksum
How to use checksums
733552216dd8e8dfbb14209ae6cfae95f597c787e1dac71a06ee0de380a7014b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page