CausalEffectEstimation.fitPStratification
- CausalEffectEstimation.fitPStratification(**estimator_params)
Fit the Propensity score Stratification Estimator.
A basic implementation of Propensity Stratification estimator based on Lunceford and Davidian[1].
- Parameters:
propensity_score_learner (
strorAny, optional) – Estimator for propensity score. If not provided, defaults to LogisticRegression.num_strata (
int, optional) – The number of strata. Default is 100.
- Raises:
MisspecifiedAdjustmentError – No adjustment, or the unknown adjustment, has been selected.
RCTError – RCT adjustment without covariate (use
pyagrum.causalEffectEstimation.CausalEffectEstimation.fitDM).ValueError – Empty backdoor adjustment set (use
pyagrum.causalEffectEstimation.CausalEffectEstimation.fitDM).FrontdoorError – A frontdoor or instrumental variable adjustment has been selected.
- Return type:
Any
Example
import numpy as np
import pandas as pd
import pyagrum as gum
import pyagrum.causalEffectEstimation as pycee
rng = np.random.default_rng(42)
X = rng.normal(size=500)
T = (rng.random(500) < 1 / (1 + np.exp(-X))).astype(int)
Y = 2 * T + X + rng.normal(size=500) # the causal effect of T on Y is 2
df = pd.DataFrame({"X": X, "T": T, "Y": Y})
cee = pycee.CausalEffectEstimation(df, gum.CausalModel(gum.fastBN("X->T->Y;X->Y")))
cee.identifyAdjustmentSet("T", "Y", verbose=False)
# 'Backdoor'
cee.fitPStratification(num_strata=10)
round(float(cee.estimateCausalEffect()), 1)
# 2.1
Class