How to get linear approximation of causal random forest?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- numpy, python, scikit-learn
- Domain
- machine-learning
Research direction
The issue provides a reproducible CausalForestDML example using effect(), with NumPy, scikit-learn, and statsmodels. Start by reviewing the CausalForestDML effect API and relevant EconML documentation, then determine whether a supported linear approximation exists beyond the proposed OLS on estimated CATEs. Done means providing a clear methodological recommendation for the multi-arm case.
Written by the indexing model from the issue text.
Description
Context
I have a multi-arm RCT. I want to run a causal random forest, and then afterwards make results more interpretable by getting a linear approximation of the results. Is there a better way than just running OLS on CATEs with robust SEs?
import numpy as np
import statsmodels.api as sm
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
from econml.dml import CausalForestDML
np.random.seed(42)
####################
# Generate data
####################
n = 2000
n_arms = 3
n_mods = 4
X = np.random.randn(n, n_mods)
W = np.random.randn(n, 2)
T = np.random.choice(n_arms + 1, size=n)
cate_true = {
1: 1.5*X[:,0] - 0.8*X[:,1],
2: 0.5*X[:,1] + 1.0*X[:,2],
3: -1.0*X[:,0] + 0.3*X[:,3],
}
Y = np.array([cate_true[t][i] if t > 0 else 0 for i, t in enumerate(T)]) \
+ X.sum(1) + np.random.randn(n)
####################
# Fit causal forest
####################
est = CausalForestDML(
model_y=RandomForestRegressor(n_estimators=200, random_state=42),
model_t=RandomForestClassifier(n_estimators=200, random_state=42),
discrete_treatment=True,
n_estimators=500,
random_state=42,
)
est.fit(Y, T, X=X, W=W)
####################
# Regress CATEs on moderators
####################
for arm in range(1, n_arms + 1):
cate_hat = est.effect(X, T0=0, T1=arm)
Xc = sm.add_constant(X)
ols = sm.OLS(cate_hat, Xc).fit(cov_type='HC3')
coef_str = ", ".join([f"X{j+1}={ols.params[j+1]:.3f} (p={ols.pvalues[j+1]:.3f})" for j in range(n_mods)])
print(f"\nArm {arm}: {coef_str}")
- Dominant language
- Jupyter Notebook
- Stars
- 4.8k
- Forks
- 827
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from py-why/EconML
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bancolombia/sentinel#21 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
infer-actively/pymdp#454 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
UKGovernmentBEIS/inspect_evals#2486 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100