Minimalistic latent correlation estimators for discretized data.
Project description
Latent Correlation Estimation Package
This package provides minimalistic implementations of latent correlation estimators between pairs of continuous variables when one or both variables are discretized.
The main goal is to offer both value-based and rank-based correlation estimates in one place, with a simple and easy-to-understand implementation.
Note: Binary data is a special case of ordinal data. For clarity, we implemented binary correlations separately as a simpler example.
Supported Estimators
1. Value-Based Correlations
- Tetrachoric
- Polychoric
- Biserial
- Polyserial
These estimators assume a bivariate normal underlying distribution and estimate the correlation parameter (rho) by maximizing the likelihood of the observed discretized data.
2. Rank-Based Correlations
- Suitable for binary, ordinal, and mixed data, and also supports continuous data through Greiner's formula
- Based on the assumption that data arises from an arbitrary monotonic transformation of underlying bivariate Gaussian variables (Gaussian copula model)
- The correlation parameter (
rho) is estimated by matching the observed Kendall's tau (rank correlation, invariant to monotonic transformations) to its expected value as a function ofrho - Can also handle continuous data (via Greiner's formula)
Usage
import numpy as np
from latentmetrics import make_corr_fn, VariableType, EstimateMethod
# Example latent data
x_latent = np.random.normal(size=100)
y_latent = 0.5 * x_latent + np.sqrt(1 - 0.5**2) * np.random.normal(size=100)
# Discretize to ordinal/binary
x_obs = np.digitize(x_latent, np.quantile(x_latent, [0.25, 0.5, 0.75]))
y_obs = np.digitize(y_latent, np.quantile(y_latent, [0.5]))
# Create correlation function and compute
corr_fn = make_corr_fn(VariableType.ORDINAL, VariableType.BINARY, method=EstimateMethod.VALUE)
result = corr_fn(x_obs, y_obs)
print("Estimated correlation:", result.estimate)
Literature & References
Value-Based Correlations
-
Polychoric correlation
Olsson, U. (1979). Maximum likelihood estimation of the polychoric correlation coefficient. Psychometrika, 44(4), 443–460. -
Polyserial correlation
Olsson, U., Drasgow, F., & Dorans, N. J. (1982). The polyserial correlation coefficient. Psychometrika, 47(3), 337–347.
Rank-Based Correlations
- Dey, D., & Zipunnikov, V. (2022). "Semiparametric Gaussian Copula Regression Modeling for Mixed Data Types (SGCRM)." arXiv preprint arXiv:2205.06868.
Copula Background
- Hofert, M., Kojadinovic, I., Mächler, M., & Yan, J. (2018). Elements of copula modeling with R. Springer.
Available Packages
R Packages
- polycor – Polychoric and Polyserial correlations
- latentcor – Efficient implementations of rank-based correlations
Python Packages
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file latentmetrics-0.1.0.tar.gz.
File metadata
- Download URL: latentmetrics-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fd615a1e28f03164fd1e7998001261232db0d20071b5da6cf2d6f4b391098a8
|
|
| MD5 |
6388916f9570fa90f89845cc0098979d
|
|
| BLAKE2b-256 |
f8d2905b960bfd9d375e93815544a96f7288ce62b06a38a9aaf8aba1a3c99111
|
Provenance
The following attestation bundles were made for latentmetrics-0.1.0.tar.gz:
Publisher:
publish.yml on PavelNovikov/latentmetrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latentmetrics-0.1.0.tar.gz -
Subject digest:
4fd615a1e28f03164fd1e7998001261232db0d20071b5da6cf2d6f4b391098a8 - Sigstore transparency entry: 819135266
- Sigstore integration time:
-
Permalink:
PavelNovikov/latentmetrics@daeb81e7e33bc7ed7b06aa489b65c6c6b86d611e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PavelNovikov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@daeb81e7e33bc7ed7b06aa489b65c6c6b86d611e -
Trigger Event:
release
-
Statement type:
File details
Details for the file latentmetrics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: latentmetrics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f685714e13d5def27007d3087767619c0f32479d45733ca776cfb0b8965d3e3
|
|
| MD5 |
c32f55db3ae295122da7db909a9d4e02
|
|
| BLAKE2b-256 |
cacec90f1bb19dbbde1b478a1bd4b9356db8d7b3bce50d9ec9894dd71042bdbd
|
Provenance
The following attestation bundles were made for latentmetrics-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on PavelNovikov/latentmetrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latentmetrics-0.1.0-py3-none-any.whl -
Subject digest:
5f685714e13d5def27007d3087767619c0f32479d45733ca776cfb0b8965d3e3 - Sigstore transparency entry: 819135279
- Sigstore integration time:
-
Permalink:
PavelNovikov/latentmetrics@daeb81e7e33bc7ed7b06aa489b65c6c6b86d611e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PavelNovikov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@daeb81e7e33bc7ed7b06aa489b65c6c6b86d611e -
Trigger Event:
release
-
Statement type: