cem
Coarsened Exact Matching for Causal Inference
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 cemuv
uv add cempoetry
poetry add cemInstalling 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
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
psmpyPsmPy implements propensity score matching for…
permissive · top 5,000 on PyPI
causalmlCausalml estimates the causal impact of…
permissive · top 15,000 on PyPI
econmlEconML estimates heterogeneous treatment…
permissive · top 15,000 on PyPI
dowhyDoWhy is a Python library for causal inference…
permissive · top 15,000 on PyPI
causallibCausallib estimates causal effects from…
permissive · top 5,000 on PyPI
empirical-calibrationComputes empirical calibration weights to…
permissive · top 15,000 on PyPI
pyhdfePyHDFE absorbs high-dimensional fixed effects…
permissive · top 15,000 on PyPI
imbalanced-learnProvides re-sampling techniques to address…
permissive · top 5,000 on PyPI
spregspreg estimates simultaneous autoregressive…
permissive · top 15,000 on PyPI
statsmodelsstatsmodels provides statistical models,…
permissive · top 1,000 on PyPI