PropensityScoreMatching<T>

Models & Types · AiDotNet.CausalInference

Implements Propensity Score Matching for causal effect estimation.

Inheritance: CausalModelBase<T> → PropensityScoreMatching<T>

For Beginners

PSM works by finding “twins” - pairs of people who were equally likely to be treated but one actually was and one wasn’t. By comparing these matched pairs, we can estimate the causal effect of treatment.

How it works:

  1. Estimate propensity scores (probability of treatment for each person)
  2. For each treated person, find a control person with the most similar propensity score
  3. Compare outcomes between matched pairs
  4. Average the differences to get the treatment effect

The key insight: If two people have the same propensity score, the “assignment” of treatment is essentially random between them. This mimics a randomized experiment.

Example - Job Training Study:

  • Person A: propensity=0.7, treated=yes, salary=$50,000
  • Person B: propensity=0.7, treated=no, salary=$45,000
  • Estimated effect: $50,000 - $45,000 = $5,000

Advantages:

  • Intuitive and easy to explain
  • Creates a matched sample that looks like a mini experiment
  • Can visually verify match quality

Limitations:

  • Discards unmatched observations
  • Sensitive to match quality
  • Only adjusts for measured confounders

References:

  • Rosenbaum & Rubin (1983). “The Central Role of the Propensity Score”

How It Works

Propensity Score Matching (PSM) estimates treatment effects by matching treated individuals to control individuals with similar propensity scores (probability of treatment).

Example

var covariates = new Matrix<double>(new double[,]
{
    { 45, 1 }, { 52, 0 }, { 38, 1 }, { 61, 0 }, { 47, 1 }, { 55, 0 }
});
var treatment = new Vector<int>(new int[] { 0, 1, 0, 1, 0, 1 });   // who was treated
var outcome = new Vector<double>(new double[] { 3.1, 7.2, 2.8, 8.0, 3.4, 7.6 });
            
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new PropensityScoreMatching<double>(caliper: 0.2, matchRatio: 1))
    .Build(covariates, treatment, outcome);
            
var (att, se) = result.EstimateATT(covariates, treatment, outcome);

Constructors

Constructor Summary
PropensityScoreMatching(double caliper, bool withReplacement, int matchRatio, int? seed) Gets the model type.

Methods

Method Summary
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) Creates a new instance with specified parameters.
ValueTuple<T, T> EstimateATE(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) Estimates the Average Treatment Effect using matched pairs.
ValueTuple<T, T> EstimateATT(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) Estimates the Average Treatment Effect on the Treated.
ValueTuple<Vector<T>, Vector<T>> GetMatchQuality(Matrix<T> x, Vector<int> treatment) Gets match quality statistics (balance check).
Vector<T> EstimateCATEPerIndividual(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) Estimates individual treatment effects using matched pairs.
Vector<T> EstimateTreatmentEffect(Matrix<T> features) Estimates treatment effects for individuals using matched pairs.
Vector<T> Predict(Matrix<T> input) Standard prediction - returns propensity scores.
Vector<T> PredictControl(Matrix<T> features) Predicts outcomes under control for the given features.
Vector<T> PredictTreated(Matrix<T> features) Predicts outcomes under treatment for the given features.
Vector<T> PredictTreatmentEffect(Matrix<T> x) Predicts treatment effects for new individuals.
int GetNumberOfMatches(Matrix<T> x, Vector<int> treatment) Gets the number of matched pairs.
void Fit(Matrix<T> features, Vector<T> treatment, Vector<T> outcome) Fits the causal model using the ICausalModel interface signature.
void Fit(Matrix<T> x, Vector<int> treatment) Fits the propensity score model to the data.