There is a newer version of the record available.

Published December 28, 2024 | Version v3
Software Open

Propensity Score Matching Python-based code

  • 1. EDMO icon University of Cantabria
  • 2. ROR icon Servicio Cántabro de Salud
  • 3. ROR icon Instituto de Investigación Marqués de Valdecilla

Description

This repository offers a free, Python-based code for performing propensity score (PS) matching. Designed for clinicians and researchers, this tool simplifies PS matching and provides comprehensive visualizations to assess matching quality. The code implements (i) Logistic regression to calculate PS, (ii) 1:N matching using the K-nearest neighbor (KNN) algorithm with a customizable caliper, (iii) sampling without replacement to ensure robust matching, and (iv) visualizations for assessing matching quality. Outputs: Matched pairs saved as a .csv file (and identified as Coxreg requires) as well as diagnostic plots saved in the specified output folder. Under the MIT License, this code was developed with assistance and refinement provided by OpenAI's ChatGPT.

Notes

The code has been tested and works with datasets in SPSS v25, 28 and 29 ('open script'). 
Python, v3.10 and 3.11.
Regarding R, versions 4.3.0 and 4.4.0, and 'Reticulate' 1.39 and 1.40. 
 
Usage
Refine the code with your current research:
- Rename C:\PATH_TO_YOUR_DATASET.sav
- Rename COVS with your data (name, not label)
- Choose the ratio (1:1, 1:2...) and the caliper 
- Rename C:\PATH_TO_YOUR_FOLDER
Run the script [RStudio, SPSS (File / Open script)...].

Files

Propensity_Score_Distribution_Density.png

Files (238.3 kB)

Name Size Download all
md5:a97623c0c51fd2e04ad4601265315055
67.7 kB Preview Download
md5:171767103c436cd40833594400ee91be
43.9 kB Preview Download
md5:43861955b4e2feb619bf6ac5b1afb34c
10.0 kB Download
md5:554b44747e0693d5914dad93230e9ee0
56.8 kB Preview Download
md5:38318e80c2af94bbc654a2c1362385e2
59.8 kB Preview Download

Additional details

Software

References

  • Staffa SJ, Zurakowski D. Five Steps to Successfully Implement and Evaluate Propensity Score Matching in Clinical Research Studies. Anesth Analg. 2018;127:1066-1073. doi: 10.1213/ANE.0000000000002787.
  • Thoemmes, F. Propensity score matching in SPSS. 2012. Available at: https://arxiv.org/pdf/1201.6385.
  • Stuart EA. Matching methods for causal inference: A review and a look forward. Stat Sci. 2010;25:1-21. doi: 10.1214/09-STS313.
  • Brookhart MA, Schneeweiss S, Rothman KJ, Glynn RJ, Avorn J, Stürmer T. Variable selection for propensity score models. Am J Epidemiol. 2006;163:1149-56. doi: 10.1093/aje/kwj149