There is a newer version of the record available.

Published December 26, 2024 | Version v1

Propensity Score Matching Python-based code

Description

This repository provides several variants of a free Python code for performing propensity score matching (PSM). 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, (iv) visualisations to assess matching quality and (v) statistics to evaluate the balance.

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), McFadden's pseudo-R², and L1 multivariate imbalance.

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. 

Files

Files (10.0 kB)

Name Size Download all
md5:43861955b4e2feb619bf6ac5b1afb34c
10.0 kB Download

Additional details