skillfed

cem

Coarsened Exact Matching for Causal Inference

cem v1.1.0 2.7M downloads/30d#2,958 on PyPI
License unclear DORMANT released

What it is and what it does

CEM is a lightweight Python library for Coarsened Exact Matching, a statistical method that improves causal inference by reducing covariate imbalance in observational data. It works by coarsening continuous and categorical predictor variables into strata, then matching or reweighting observations to balance treatment and control groups. The library provides automatic and manual coarsening workflows, implements L1 and L2 multivariate imbalance measures, and produces observation weights suitable for downstream regression analysis.

The package is designed for researchers and analysts working with observational studies who need treatment effect estimates that are robust to model specification. It depends only on pandas and numpy, making it lightweight and easy to integrate into existing data analysis pipelines. Users typically coarsen their data, apply matching to generate weights, measure resulting imbalance, and use those weights in weighted regression models.

Use it for:

  • Reduce covariate imbalance in observational studies before estimating treatment effects.
  • Generate observation weights for weighted regression to improve causal inference robustness.
  • Compare L1 and L2 imbalance measures across different coarsening strategies.
  • Preprocess data for causal inference when alternative matching is not suitable.
  • Validate that matched samples have acceptable covariate balance before analysis.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Implements Coarsened Exact Matching (CEM), a statistical matching technique that reduces covariate imbalance in observational data to produce more stable causal treatment effect estimates.

Yes, if you are conducting causal inference with observational data and need a lightweight, dependency-minimal matching technique. The package has no known vulnerabilities and low install friction. However, the dormant maintenance status and unclear license terms warrant verification before production use. Suitable for research and academic work; exercise caution in proprietary contexts until license is clarified.

Install

cem on PyPI

pip

pip install cem

uv

uv add cem

poetry

poetry add cem

Installing cem

Before you install

Low friction installation with only pandas and numpy as runtime dependencies. Package is dormant (last release 2023-10-12) with no recent maintenance signal, though it remains compatible with Python 3.9–3.12.

License in practice

License treatment is unclear—no SPDX identifier or raw license text is available in the package metadata. Verify the actual license terms before use in proprietary or restricted contexts.

Quickstart

pip install cem

from cem.match import match
from cem.coarsen import coarsen
from cem.imbalance import L1
import pandas as pd

X_coarse = coarsen(X, T, "l1")
weights = match(X_coarse, T)
imbalance = L1(X_coarse, weights)

Requires Python >=3.9,<3.13; pandas and numpy must be installed.

Verify before relying

  • Whether the dormant status signals abandonment risk or stable maintenance.
  • Actual license terms and conditions (SPDX identifier and full license text not provided).
  • Performance characteristics and scalability limits for large datasets.
  • How CEM results compare to other matching techniques in practice.

Package facts

License not declared (unclear)
Python support capped below the current Python release (>=3.9,<3.13)
Install friction low — pure-Python wheel
Runtime dependencies 2 — pandas, numpy
Maintenance dormant — 1,037 days since the last release
First released
Downloads 2,653,150/month — #2,958 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: cem-1.1.0-py3-none-any.whl

Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9

Tags

coarsened exact matchingcausal inference matchingcovariate imbalance reductiontreatment effect estimationobservational study matchingpropensity score alternativeL1 L2 imbalance measures
causal-inferencematching-methodsobservational-studies

More Scientific/Engineering packages

Further reading