Propensity Score Matching Python-based code
Authors/Creators
Description
This repository provides 4 versions of a free, Python-based code for performing propensity score (PS) matching. An initiative of the Camargo Cohort Study, developed with the aim of sharing the tool and spreading the use of PS matching.
The code overcomes compatibility issues with R versions and R packages, and implements (i) logistic regression to compute PS, (ii) 1:N matching using the K-nearest neighbour (KNN) algorithm with a customisable caliper, (iii) sampling with or without replacement, and (iv) visualisations to assess matching quality.
Outputs:
- Matched pairs stored as '.csv' file, allowing a Coxreg to be performed ('SET' in SPSS).
- Diagnostic plots stored in the specified output folder, providing a view of SMD and PS distribution.
- Statistics for matching validation: SMD, variance ratio (VR), and McFadden's pseudo-R^2.
The code has been developed using information from the Matplotlib, Numpy and Seaborn libraries and with OpenAI's ChatGPT support and refinements.
No funding was received for conducting this work and there are no financial or non-financial interests to disclose.
Notes
Notes
Files
Figure_1.png
Files
(226.6 kB)
| Name | Size | Download all |
|---|---|---|
|
md5:ef269c09c403a30538e2f9cc821c6570
|
46.2 kB | Preview Download |
|
md5:48263ac797d6ea828b92b51e4dd80729
|
10.8 kB | Download |
|
md5:d871cfd950226f0c758d2157a119dec7
|
11.3 kB | Download |
|
md5:a7a4280f8e69a9b0b149c4cdf60a2fb2
|
8.3 kB | Download |
|
md5:4a7ec2ec49d25b0960c29736badee9ce
|
7.5 kB | Download |
|
md5:0ad0391808cf4fb1070857ee12787671
|
63.9 kB | Preview Download |
|
md5:1dfed3ff74f225bf1e1d22541f499f42
|
78.5 kB | Preview Download |
Additional details
Dates
- Updated
-
2025-01-27Python-based code for implementing PSM
Software
- Repository URL
- https://github.com/epsar-co/Propensity-Score-Matching-Python-based-code.git
- Programming language
- Python
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.