Skip to main content

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 of rho
  • 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

  • latentcor – Efficient rank-based correlations from the authors of the R package
  • semopy – Structural Equation Modeling (SEM) package; includes polychoric and polyserial correlations

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

latentmetrics-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latentmetrics-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

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

Hashes for latentmetrics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4fd615a1e28f03164fd1e7998001261232db0d20071b5da6cf2d6f4b391098a8
MD5 6388916f9570fa90f89845cc0098979d
BLAKE2b-256 f8d2905b960bfd9d375e93815544a96f7288ce62b06a38a9aaf8aba1a3c99111

See more details on using hashes here.

Provenance

The following attestation bundles were made for latentmetrics-0.1.0.tar.gz:

Publisher: publish.yml on PavelNovikov/latentmetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for latentmetrics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f685714e13d5def27007d3087767619c0f32479d45733ca776cfb0b8965d3e3
MD5 c32f55db3ae295122da7db909a9d4e02
BLAKE2b-256 cacec90f1bb19dbbde1b478a1bd4b9356db8d7b3bce50d9ec9894dd71042bdbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for latentmetrics-0.1.0-py3-none-any.whl:

Publisher: publish.yml on PavelNovikov/latentmetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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