py-why / EconML

ALICE (Automated Learning and Intelligence for Causation and Economics) is a Microsoft Research project aimed at applying Artificial Intelligence concepts to economic decision making. One of its goals is to build a toolkit that combines state-of-the-art machine learning techniques with econometrics in order to bring automation to complex causal inference problems. To date, the ALICE Python SDK (econml) implements orthogonal machine learning algorithms such as the double machine learning work of Chernozhukov et al. This toolkit is designed to measure the causal effect of some treatment variable(s) t on an outcome variable y, controlling for a set of features x.
https://www.microsoft.com/en-us/research/project/alice/
Other
3.87k stars 719 forks source link

How to use LinearDML and causalforestDML to get CATE #926

Open GladysKao opened 3 weeks ago

GladysKao commented 3 weeks ago

Hi, I'm new to this. I want to know if the coef I have got in LinnearDML is CATE? If not, what these coef mean? where can I get CATE when I use causalforestDML? I'm so confused...I have read doc for many times but I still can't get CATE values. In my opinion, I think CATE is the effect when X_i=1 and other features all equal to 1 or 0....is anything wrong about my definition about CATE? Thank you~

(or if I use marginal_effect['CATE']=est.marginal_effect(T, X), and then marginal_effect.groupby(X_i)['CATE'].mean(), can I get CATE through this way?)

kbattocchi commented 3 weeks ago

In general, the CATE is the Conditional Average Treatment Effect, of going from some treatment T0 to some other treatment T1, given some set of features X.

For all of our estimators, this can be gotten by calling est.effect(X, T0, T1). In the case of LinearDML, this is derived from coef_ (and intercept_, if fit_cate_intercept is True), but they are not identical (the coef_ entries are the coeffcients of the CATE on the feature/treatment interactions).

Most of our estimators are linear in the treatment, and often there is a single treatment, in which case the marginal effect is just a scalar function of X independent of T, and so est.const_marginal_effect(X) will provide you with the marginal effect (basically, the effect of going from treatment=0 to treatment=1, which you can then scale to other treatment differences accordingly).

GladysKao commented 3 weeks ago

Thank you for your reply. I think I have a misunderstanding about CATE. I misunderstood CATE is for just ONE feature not a set of features. But for that I met a new problem, if I have five features, and then I want to obtain ATE for each feature, what can I do? Does TreeCateInterpreter will help? My code is : results_cf = X.copy() cate_cf=est_cf.effect(X) results_cf['CATE']=cate_cf for x in est_lr.cate_feature_names(): average_cate_lr = results_lr.groupby(x)['CATE'].mean() print(average_cate_lr) The output is : ... peak 0 0.252617 1 0.103567 Name: CATE, dtype: float64 ...

and then I called SingleTreeCateInterpreter: 微信图片_20241107182336

I found CATE of the feature which be uesd to spilt first is the same as my output. so I really want to know if my output "average_cate_lr" has its owen meaning. or I just want to know how to interpret each CATE in each node. Does it represent the causal effect between T and Y when condition is X_i or a combination of X_i, ... ,X_j.

I mean, if I have five features: passenger, violate, distract, weekend and peak. I got a treeinterpreter and CATE for each node, assuming that the split step is "peak weekend distract....." Can I say"when peak, CATE is 0.103567, when not peak ,CATE is 0.252617, when peak and weekend, CATE is..., when peak and not weekend, CATE is..., When not peak and distract...."
I want to know the meaning of each CATE, I think each CATE has its own meaning. Look forward to your reply, Thank you~

GladysKao commented 3 weeks ago

CORRECTION: results_cf = X.copy() cate_cf=est_cf.effect(X) results_cf['CATE']=cate_cf for x in est_cf.cate_feature_names(): average_cate_cf = results_cf.groupby(x)['CATE'].mean() print(average_cate_cf) Sorry for my mistake, the model I used is causalforestDML

GladysKao commented 2 weeks ago

Or shortly, @kbattocchi How can I understand the results of treeinterpreter.

And I even can use treeinterpreter for LinearDML, I know GRF create the split structure by maximizing the heterogeneity for each spilt. But how do LinearDML create the split structure?

Big thanks in advance.

kbattocchi commented 2 weeks ago

If you have multiple columns in X, the CATE is giving you an estimate of the effect of T on Y conditional on all of the features in X simultaneously. In general, for CausalForestDML, this will be some complicated function of X, while for LinearDML this will just be a linear function of X (which coef_ gives you the coefficients for).

SingleTreeCateInterpreter is one way to try to get a simplified view of any learned CATE model - it will give you a tree that has just a handful of nodes, making it easy to interpret, but the tradeoff is that it will give you rougher estimates of the CATE because it averages together units that the underlying model would assign different individual CATEs. However, this tradeoff might be worthwhile if you need a very high level understanding of which units have very different effects from each other, rather than more precise estimates for each unit.