Skip to main content

tlf-correlation-engine

Country-agnostic correlation analysis — part of TLF ("The Living Facts").

Computes Pearson, Spearman, or Kendall correlations across any pandas DataFrame's numeric columns, along with p-values and observation counts, and produces a sorted, filterable long-form report of the strongest and most statistically significant relationships in a dataset.

Unlike tlf-census-stats, this package has no dependency on a specific country schema — it works on any DataFrame with 2+ numeric columns.


Install

pip install tlf-correlation-engine

Or from source, inside the TLF-Data-Analysis monorepo:

cd tlf-correlation-engine
pip install -e ".[dev]"

Usage

import pandas as pd
from tlf_correlation_engine import CorrelationEngine

df = pd.read_csv("census_data.csv")

engine = CorrelationEngine(df, method="pearson")  # or "spearman" / "kendall"

# Coefficient matrix (like df.corr(), but validated numeric-only)
engine.matrix()

# P-value matrix, aligned with matrix()
engine.pvalue_matrix()

# One specific pair, with n and p-value
engine.pairwise("literacy_rate", "urban_population")

# Long-form report of all pairs, strongest relationship first
engine.report()

# Only strong (|r| >= 0.5) and statistically significant (p < 0.05) pairs
engine.report(threshold=0.5, significant_only=True)

Methods

Method Use for
pearson Linear relationships between continuous variables
spearman Monotonic (rank-based) relationships, robust to outliers/non-linearity
kendall Rank concordance, more robust on small samples or many tied ranks

CLI

tlf-correlation-engine --data census.csv --method spearman --output report --export csv --export-path out.csv

Run with no flags at all for a fully interactive walkthrough (file path → sheet selection → method → output type → report filters → export format):

tlf-correlation-engine

For unattended/scripted runs, --yes disables all prompting and fails loudly (rather than silently guessing) if something required — like --data — is missing:

tlf-correlation-engine --data census.csv --yes --method pearson --output matrix

CLI flags

Flag Description
--data Path to a CSV, Excel, or JSON file
--sheet Excel sheet name (default: first sheet)
--method pearson | spearman | kendall
--output report | matrix | pvalues
--threshold Report only: minimum |coefficient| to include
--significant-only Report only: only include pairs with p < --alpha
--alpha Significance threshold for --significant-only (default 0.05)
--export csv | json
--export-path Export file path
--yes Non-interactive mode: never prompt, error on missing required values

Errors

  • InvalidMethodError — unsupported method value
  • InsufficientDataError — fewer than 2 numeric columns in the DataFrame

License

MIT — see LICENSE.

Release files for tlf-correlation-engine 0.1.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 tlf-correlation-engine 0.1.0
File Size Uploaded
tlf_correlation_engine-0.1.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tlf-correlation-engine 0.1.0
File Interpreter ABI Platform
tlf_correlation_engine-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / tlf_correlation_engine-0.1.0.tar.gz

Download URL tlf_correlation_engine-0.1.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
513c33d976f655a3dc44826a59fe5c3a23bdf3ce4ff60ab647e05970d2eaf4f1
BLAKE2b-256 checksum
How to use checksums
f5bfd1623197338c3a943e9fc1738a2bbaae1385577f6f3af69249e651d9f230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / tlf_correlation_engine-0.1.0-py3-none-any.whl

Download URL tlf_correlation_engine-0.1.0-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3a680c9adfde97baca8075cc00428167060c6fd4ee90cd503abde4a3c2a755b
BLAKE2b-256 checksum
How to use checksums
878a49d2245b9f4c55dab2da59d4237ae4f5de3f9154cf7b6236a929bc560045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

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