Skip to main content

PyPI version Total alerts Language grade: Python

korr

collection of utility functions for correlation analysis

Usage

Check the examples folder for notebooks.

Compute correlation matrix and its p-values

  • pearson – Pearson/Sample correlation (interval- and ratio-scale data)

  • kendall – Kendall’s tau rank correlation (ordinal data)

  • spearman – Spearman rho rank correlation (ordinal data)

  • mcc – Matthews correlation coefficient between binary variables

EDA, Dig deeper into results

  • flatten – A table (pandas) with one row for each correlation pairs with the variable indicies, corr., p-value. For example, try to find “good” cutoffs with corr_vs_pval and then look up the variable indicies with flatten afterwards.

  • slice_yx – slice a correlation and p-value matrix of a (y,X) dataset into a (y,x_i) vector and (x_j, x_k) matrices

  • corr_vs_pval – Histogram to find p-value cutoffs (alpha) for a) highly correlated pairs, b) unrelated pairs, c) the mixed results.

  • bracket_pval – Histogram with more fine-grained p-value brackets.

  • corrgram – Correlogram, heatmap of correlations with p-values in brackets

Utility functions

  • confusion – Confusion matrix. Required for Matthews correlation (mcc) and is a bitter faster than sklearn’s

Parameter Stability

  • bootcorr – Estimate multiple correlation matrices based on bootstrapped samples. From there you can assess how stable correlation estimates are (how sensitive against in-sample variation). For example, stable estimates are good candidates for modeling, and unstable correlation pairs are good candidates for P-hacking and non-reproducibility.

Variable Selection, Search Functions

  • mincorr – From all estimated correlation pairs, pick a given n=3,5,.. of variables with low and insignificant correlations among each other. (See binsel package for an application.)

  • find_best – Find the N “best”, i.e. high and most significant, correlations

  • find_worst – Find the N “worst”, i.e. insignificant/random and low, correlations

  • find_unrelated – Return variable indicies of unrelated pairs (in terms of insignificant p-value)

Appendix

Installation

The korr git repo is available as PyPi package

pip install korr

Install a virtual environment

python3.7 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt --no-cache-dir
pip install -r requirements-dev.txt --no-cache-dir
pip install -r requirements-demo.txt --no-cache-dir

(If your git repo is stored in a folder with whitespaces, then don’t use the subfolder .venv. Use an absolute path without whitespaces.)

Commands

  • Check syntax: flake8 --ignore=F401

  • Run Unit Tests: pytest

  • Remove .pyc files: find . -type f -name "*.pyc" | xargs rm

  • Remove __pycache__ folders: find . -type d -name "__pycache__" | xargs rm -rf

Publish

pandoc README.md --from markdown --to rst -s -o README.rst
python setup.py sdist
twine upload -r pypi dist/*

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

Metadata

Release files for korr 0.10.0

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

Source distribution (sdist)

Source distribution for korr 0.10.0
File Size Uploaded Provenance Actions
korr-0.10.0.tar.gz 17.2 kB Without provenance Details for korr-0.10.0.tar.gz

Release files / korr-0.10.0.tar.gz

Download URL korr-0.10.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eb7de8f76806c1442da3a847ad41c33aa68679d3ba185f4762523ce298466a22
BLAKE2b-256 checksum
How to use checksums
dd50f4fc307d6ac91e11052bff5bc35cf08e6245660931123f4003ee68dc5b0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.8.3 requests/2.28.0 setuptools/62.5.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.7.9

Security for korr 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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