psm: propensity score matching

Propensity score matching with psmpy and a report of the covariate balance. psm estimates propensity scores by logistic regression and matches every treated observation to its nearest control on the logit of the score; psm_effect_size reports the standardized mean differences before and after matching.

from apatools.psm import psm, psm_effect_size

results, model = psm(
    data,
    treatment_variable="vs",
    include_vars=["age", "gender"],
    balance=True,
    replacement=True,
    seed=1,
    return_model=True,
)
print(psm_effect_size(model))

Design choices and caveats

  • No caliper. Matching without a caliper can pair dissimilar observations. Austin (2011) recommends a caliper of 0.2 standard deviations of the logit of the propensity score; psm does not apply one. Check the balance with psm_effect_size and, if it is poor, restrict the sample yourself.

  • Balance is measured as Cohen’s d with the pooled standard deviation, |mean_treated − mean_control| / √(((n₁−1)s₁² + (n₀−1)s₀²)/(n₁+n₀−2)). Values below about 0.1 after matching are commonly taken to indicate adequate balance (Austin, 2011); that is a convention, not a test.

  • A zero pooled standard deviation (a constant covariate) makes psmpy divide by 1e-6, which gives a very large value for any difference.

  • Covariates must be numeric: they are cast to float, so dummy-code categorical variables first.

  • Reproducibility. seed is passed on to psmpy’s own sampling (used with balance=True and unequal groups).

  • What it is not. A propensity score method removes the imbalance of the observed covariates in the matched sample; it says nothing about unobserved confounding.

Where it differs from R

R’s MatchIt offers the same family of methods with many more options (calipers, other distance measures, exact matching). apatools does not reproduce MatchIt; psmpy’s defaults (logistic scores, nearest neighbour on the logit) are what you get.

Checked against

tests/test_psm.py runs the example of psmpy (the mtcars data) and checks that matching reduces the standardized differences and that a fixed seed reproduces the result. There is no comparison with R.

Literature

The references cited in the docstrings of the functions of this module (they are collected from the docstrings when the documentation is built; the software that does the work is on the software page).

  • Austin, P. C. (2011). An introduction to propensity score methods for reducing the effects of confounding in observational studies. Multivariate Behavioral Research, 46(3), 399-424. https://doi.org/10.1080/00273171.2011.568786

  • Austin, P. C. (2011). Optimal caliper widths for propensity-score matching when estimating differences in means and differences in proportions in observational studies. Pharmaceutical Statistics, 10(2), 150-161. https://doi.org/10.1002/pst.433

  • Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates. (Reprinted 2013 by Routledge, https://doi.org/10.4324/9780203771587)

  • Kline, A., & Luo, Y. (2022). PsmPy: A package for retrospective cohort matching in Python. 2022 44th Annual International Conference of the IEEE Engineering in Medicine & Biology Society (EMBC) (pp. 1354-1357). https://doi.org/10.1109/EMBC48229.2022.9871333

  • Rosenbaum, P. R., & Rubin, D. B. (1983). The central role of the propensity score in observational studies for causal effects. Biometrika, 70(1), 41-55. https://doi.org/10.1093/biomet/70.1.41