Skip to content
svgoverlap-density

Propensity score overlap

Do treated and control units share a range of propensity scores (overlap / positivity)?

Demo data · seed 20261101 · 900 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the top and bottom histograms as each group's propensity scores.
  2. Check that they cover the same range: that's the shaded common support.
  3. Compare the outline after weighting.
  1. Callout 1: Treated units.
  2. Callout 2: Control units.
  3. Callout 3: The common-support region.

Watch out

  • Few controls at high propensity scores makes results depend on extreme weights.

Defaults

Mirror the second group
On
Flip the second group below the axis, so shapes can be compared.
Bins
25
How many bins to divide the range into.
Range 5 to 80, step 1

Pinned in the code

  • Draws the scores the engine estimated; the chart bins them on shared edges ([0, 1] when every score lies in it) and scales each group to a density.
  • Common support = [max of the group minimums, min of the group maximums]; little mass outside it means weights and matches rely less on extrapolation.
  • With a weight role, the outlines are the weighted densities (e.g. ATT or overlap weights) on the same bins.
# Propensity score overlap — Codesplash Chart Lab (recipe "overlap-density")
# controls: mirrored=true, bins=25
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("overlap-density-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["group"] = pd.Categorical(df["group"].astype("string"), categories=["treated", "control"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
S = "propensity score"
G = "group"
W = "ATT weight"
BINS, MIRRORED = 25, True
d = df.dropna(subset=[S, G])
groups = levels_of(d[G].astype(str))[:2]
lo, hi = (0, 1) if d[S].between(0, 1).all() else (d[S].min(), d[S].max())
edges = np.linspace(lo, hi, BINS + 1)  # shared edges
fig, ax = plt.subplots(figsize=(8, 4.5))
for i, g in enumerate(groups):
    s = d.loc[d[G].astype(str) == g, S]
    dens, _ = np.histogram(s, bins=edges, density=True)
    sign = -1 if (MIRRORED and i == 1) else 1
    ax.bar(edges[:-1], sign * dens, width=np.diff(edges), align="edge", color=PALETTE[i], alpha=0.65, label=g)
    if W:
        wd, _ = np.histogram(s, bins=edges, weights=d.loc[d[G].astype(str) == g, W], density=True)
        ax.stairs(sign * wd, edges, color="black", linewidth=1.2)
ax.axhline(0, color="grey", linewidth=0.8)
ax.set_xlabel(S)
ax.set_ylabel("density")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads overlap-density-demo.csv · app theme from the optional codesplash helper