DoublyRobustEstimator<T>

Models & Types · AiDotNet.CausalInference

Implements the Doubly Robust (DR) estimator for causal effect estimation.

Inheritance: CausalModelBase<T> → DoublyRobustEstimator<T>

For Beginners

The DR estimator is like having two insurance policies:

  1. Outcome Model: Predicts outcomes based on features and treatment
  2. Propensity Model: Predicts who gets treated

If either model is correct, you get unbiased treatment effect estimates. This “double protection” makes DR very popular in practice.

The formula combines:

  • Predicted outcomes (if we trust the outcome model)
  • IPW-adjusted residuals (correction if outcome model is wrong)

DR estimator: τ̂ = (1/n) Σ [μ₁(Xᵢ) - μ₀(Xᵢ)] + (1/n) Σ [Tᵢ(Yᵢ - μ₁(Xᵢ))/e(Xᵢ) - (1-Tᵢ)(Yᵢ - μ₀(Xᵢ))/(1-e(Xᵢ))]

Where:

  • μ₁(X), μ₀(X) = predicted outcomes under treatment/control
  • e(X) = propensity score
  • T = treatment indicator
  • Y = observed outcome

The first term uses the outcome model predictions. The second term “corrects” using IPW when the outcome model is wrong.

Advantages:

  • Doubly robust: consistent if either model is correct
  • More efficient than IPW alone when both models are good
  • Semiparametric efficiency (achieves best possible variance)

References:

  • Robins, Rotnitzky & Zhao (1994). “Estimation of Regression Coefficients”
  • Bang & Robins (2005). “Doubly Robust Estimation”

How It Works

The Doubly Robust estimator combines outcome regression with propensity score weighting, providing consistent estimates if EITHER the outcome model OR the propensity model is correct.

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 DoublyRobustEstimator<double>(trimMin: 0.01, trimMax: 0.99))
    .Build(covariates, treatment, outcome);
            
var (ate, se) = result.EstimateATE(covariates, treatment, outcome);

Constructors

Constructor Summary
DoublyRobustEstimator(double trimMin, double trimMax, bool useCrossFitting, int numFolds, int? randomSeed) Initializes a new instance of the DoublyRobustEstimator class.

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 the Doubly Robust estimator.
ValueTuple<T, T> EstimateATT(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) Estimates the Average Treatment Effect on the Treated.
Vector<T> EstimateCATEPerIndividual(Matrix<T> x, Vector<int> treatment, Vector<T> outcome) Estimates individual treatment effects.
Vector<T> EstimateTreatmentEffect(Matrix<T> features) Estimates treatment effects for individuals using the doubly robust estimator.
Vector<T> Predict(Matrix<T> input) Standard prediction - returns predicted treatment effects.
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.
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, Vector<T> outcome) Fits the causal model using the ICausalModel interface signature.