Skip to main content

Compute correlation coefficients with uncertainties

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymccorrelation-0.2.4.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

pymccorrelation-0.2.4-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file pymccorrelation-0.2.4.tar.gz.

File metadata

  • Download URL: pymccorrelation-0.2.4.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pymccorrelation-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0a5f1690dd9bd5b756c536e8d497747881439a9b62ab521bc8d618a59b3e11e8
MD5 c8e9a2d18911d2a7436141b5a432a8b4
BLAKE2b-256 45f6e7760e75e20471c8b094367182967d8990c909d68440d37dbf41011863b2

See more details on using hashes here.

File details

Details for the file pymccorrelation-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: pymccorrelation-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pymccorrelation-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e7089732b47f1b60ef68bd7abfda214aded9b442e285a58f0810f81286af6b64
MD5 7357e564a4ca8736cf7d991a9da04428
BLAKE2b-256 2e49fbf2d0efa7f40c8b84324505152ab36aa870bdf0019d205995ffd1eb8c89

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page