DML ATT Example

DML ATT Example

This notebook covers scenario: | Is RCT | Treatment | Outcome | EDA | Estimands | Refutation | |---------------|-----------|------------|-----|-----------|------------| | Observational | Binary | Continuous | Yes | ATT | Yes |

We will estimate Average Treatment Effect on Treated (ATT) of binary treatment on continuous outcome. It shows explonatary data analysis and refutation tests

Generate data

Example that generates observational data with a nonlinear outcome model, nonlinear treatment assignment, and a heterogeneous (nonlinear) treatment effect tau(X). This setup ensures that ATT ≠ ATE in general. It also shows how to compute the “ground-truth” ATT from the generated data.

Result

Ground-truth ATT from the DGP: 1.386

ydtenure_monthsavg_sessions_weekspend_last_monthpremium_userurban_resident
02.2373160.027.6566055.35255472.5525681.00.0
15.7714690.011.5201916.798247188.4812871.00.0
26.3746531.033.0054142.05545951.0404400.01.0
32.3641771.035.2867774.429404166.9922390.01.0
48.3780790.00.5875786.658307179.3711260.00.0

EDA

General dataset information

Let's see how outcome differ between clients who recieved the feature and didn't

Result

{'n_rows': 10000, 'n_columns': 7}

Result
countmeanstdminp10p25medianp75p90max
treatment
0.065303.1871973.754761-12.770866-1.5792040.6995713.1492155.7204437.93163517.323664
1.034705.2224633.986593-7.3105140.1517412.5086515.2052427.97518910.35116918.147842
Result

png

Propensity

Now let's examine how propensity score differ treatments

Result
mean_t_0mean_t_1abs_diffsmd
confounders
spend_last_month90.260494119.48610529.2256110.526811
premium_user0.1947930.3550430.1602500.364805
avg_sessions_week4.9037635.2984050.3946420.197681
urban_resident0.5768760.6461100.0692340.142388
tenure_months23.33640324.8943231.5579200.129076
Result

ROC AUC from PropensityModel: 0.6962

Result

Positivity check from PropensityModel: {'bounds': (0.05, 0.95), 'share_below': 0.0121, 'share_above': 0.0004, 'flag': False}

Result
featureshap_meanshap_mean_absexact_pp_change_absexact_pp_change_signed
0num__spend_last_month-0.0003400.5684710.136983-0.000077
1num__tenure_months0.0002920.1753480.0406840.000066
2num__premium_user0.0001200.3493190.0826730.000027
3num__urban_resident-0.0001030.1692250.039233-0.000023
4num__avg_sessions_week0.0000310.2302360.0537830.000007
Result

png

Outcome regression

Let's analyze how confounders predict outcome

Result

{'rmse': 3.645288976705851, 'mae': 2.905875481642826}

Result
featureshap_mean
0premium_user0.001576
1spend_last_month-0.001158
2avg_sessions_week-0.000562
3urban_resident0.000089
4tenure_months0.000055

Inference

Now time to estimate ATTE with Double Machine Learning

Result

1.3028994051092602 0.0 (1.0561145643875967, 1.5496842458309237)

Real ATT is 1.385

Refutation

Overlap

Result
metricvalueflag
0edge_0.01_below0.000000GREEN
1edge_0.01_above0.000000GREEN
2edge_0.02_below0.001300GREEN
3edge_0.02_above0.000000GREEN
4KS0.291272YELLOW
5AUC0.696701GREEN
6ESS_treated_ratio0.632449GREEN
7ESS_control_ratio0.795967GREEN
8tails_w1_q99/med10.777459YELLOW
9tails_w0_q99/med6.571975YELLOW
10ATT_identity_relerr0.070511YELLOW
11clip_m_total0.000000GREEN
12calib_ECE0.019505GREEN
13calib_slope0.815776GREEN
14calib_intercept-0.097113GREEN

Score

Result
metricvalueflag
0se_plugin0.125913NA
1psi_p99_over_med8.868324GREEN
2psi_kurtosis1388.840488RED
3max_|t|_g10.000000GREEN
4max_|t|_g02.484521YELLOW
5max_|t|_m1.165779GREEN
6oos_tstat_fold-0.000402GREEN
7oos_tstat_strict-0.000402GREEN

SUTVA

Result

1.) Are your clients independent (i)? 2.) Do you measure confounders, treatment, and outcome in the same intervals? 3.) Do you measure confounders before treatment and outcome after? 4.) Do you have a consistent label of treatment, such as if a person does not receive a treatment, he has a label 0?

Uncofoundedness

Result
metricvalueflag
0balance_max_smd3.963837e-02GREEN
1balance_frac_violations0.000000e+00GREEN
2ess_treated_ratio1.000000e+00GREEN
3ess_control_ratio3.390213e-01RED
4w_tail_ratio_treated1.000000e+12RED
5w_tail_ratio_control1.321510e+01GREEN
6top1_mass_share_treated2.881844e-02GREEN
7top1_mass_share_control1.242615e-01GREEN
8ks_m_treated_vs_control2.912719e-01YELLOW
9pct_m_outside_overlap0.000000e+00GREEN
Result

{'theta': 1.3028994051092602, 'se': 0.12591294670120004, 'level': 0.95, 'z': 1.959963984540054, 'sampling_ci': (1.0561145643875967, 1.5496842458309237), 'theta_bounds_confounding': (1.2323591117099104, 1.37343969850861), 'bias_aware_ci': (0.985574270988247, 1.6202245392302732), 'max_bias': 0.07054029339934965, 'sigma2': 13.23191609168223, 'nu2': 0.31385839388470366, 'params': {'cf_y': 0.01, 'cf_d': 0.01, 'rho': 1.0, 'use_signed_rr': False}}

Result
cf_ycf_drhotheta_longtheta_shortdelta
d0.0000070.034929-1.01.3028991.408257-0.105358