There is a newer version of the record available.

Published January 10, 2025 | Version v4
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 
- Choose bar colors and adjust the limits of the x-axis and y-axis to the desired range
- Rename C:\PATH_TO_YOUR_FOLDER
Run the script [RStudio, SPSS (File / Open script)...].

Files

Barplot.png

Files (139.3 kB)

Name Size Download all
md5:026add5d1e69175509e37676cdeea907
58.8 kB Preview Download
md5:f8c77a472413f4f89f30b5d7a933568a
60.3 kB Preview Download
md5:53d835f86bad5c7645ab1131a5b28185
10.1 kB Download
md5:43861955b4e2feb619bf6ac5b1afb34c
10.0 kB Download

Additional details

Dates

Updated
2025-01-10

Software