Skip to content

brycewang-stanford/Auto-Empirical-Research-Skills / skills/11-James-Traina-compound-science/skills/causal-ml

causal-ml

Verified

This skill covers causal machine learning methods in applied economics and quantitative social science. Use when implementing or choosing between modern ML-based causal estimators — including double machine learning, DML, partially linear models, interactive regression models, cross-fitting, Neyman orthogonality, debiased ML, causal forests, generalized random forest, GRF, honest causal trees, AIPW with machine learning, doubly robust with machine learning, DR-Learner, T-Learner, S-Learner, X-Learner, meta-learners, heterogeneous treatment effects, conditional average treatment effect, CATE, HTE, high-dimensional controls, LASSO controls, post-LASSO, post-double selection, Belloni-Chernozhukov-Hansen, Riesz representer, Chernozhukov, sample splitting, econml, DoubleML package, or any combination of machine learning and causal inference.

references/connections-traditional.md

View on GitHub
# Connections to Traditional Methods — Reference

Understanding how causal ML relates to traditional methods helps build intuition and credibility with traditional audiences.

## DML Reduces to IV When Nuisance Models Are Linear

If E[Y|X] and E[D|X] are both estimated by OLS (linear projections), then DML's partialling out is numerically identical to the Frisch-Waugh-Lovell theorem. The DML θ̂ equals the OLS coefficient on D in a regression of Y on D and X.

This means: DML with linear nuisance models = standard OLS. DML adds value precisely when the nuisance functions are nonlinear — it allows flexible control for X while maintaining √n-inference on θ.

**Practical check:** Run DML with linear nuisance models (OLS) and compare to OLS with all controls. They should match. If not, there is a coding error.

## IV with DML Nuisance Models

DML extends naturally to IV. The partially linear IV model:

```
Y = θ₀ D + g₀(X) + ε
D = m₀(X) + v
Z: instrument with E[Z · ε | X] = 0
```

Cross-fitted IV moment: regress residualized Y on residualized D, instrumenting with residualized Z.

```python
# DoubleML: Partially linear IV
pliv = dml.DoubleMLPLIV(
    obj_dml_data=data,   # data must include Z (instrument)
    ml_g=ml_g,           # learner for E[Y|X]
    ml_m=ml_m,           # learner for E[D|X]
    ml_r=ml_r,           # learner for E[Z|X]  — partialling out Z
    n_folds=5,
)
pliv.fit()
print(pliv.summary)
```

## Causal Forests Generalize Local ATE

Standard IV/2SLS at a single instrument value (e.g., an RDD cutoff) gives LATE for compliers at that point. A causal forest with an instrument generalizes this to heterogeneous LATE across the covariate space:

```r
# R: grf — instrumental forest
iv_forest <- instrumental_forest(
  X = X_matrix,
  Y = Y_vector,
  W = W_treatment,   # endogenous treatment
  Z = Z_instrument,  # instrument
  seed = 42
)
tau_late_hat <- predict(iv_forest)$predictions
ate_late <- average_treatment_effect(iv_forest)
```

## Post-LASSO Generalizes 2SLS with Many Instruments

The many-instruments problem (Bekker 1994) causes 2SLS to be inconsistent when the number of instruments grows with n. Post-LASSO selects a sparse set of strong instruments, then runs standard 2SLS on the selected instruments. This connects to LIML and jackknife IV estimators.

```r
# R: hdm — LASSO for many instruments
# First, select relevant instruments using LASSO
lasso_z <- rlasso(D_vector ~ Z_matrix)  # regress D on instruments
selected_z <- which(lasso_z$coef != 0)

# Then run 2SLS with selected instruments
library(fixest)
iv_formula <- as.formula(
  paste("Y ~", paste(X_names, collapse = "+"),
        "| D ~ ", paste(Z_names[selected_z], collapse = "+"))
)
result_iv <- feols(iv_formula, data = df, vcov = "hetero")
print(result_iv)
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall