Editing
Causal Inference in AI
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''Estimating causal treatment effects with DoWhy:''' <syntaxhighlight lang="python"> import dowhy from dowhy import CausalModel import pandas as pd import numpy as np # Generate synthetic data: drug β recovery, age β both drug and recovery (confounder) np.random.seed(42) n = 1000 age = np.random.normal(50, 15, n) drug = (0.3 * age + np.random.normal(0, 10, n) > 30).astype(int) # older β more likely to receive drug recovery = 0.5 * drug - 0.02 * age + np.random.normal(0, 1, n) # drug helps, but age hurts df = pd.DataFrame({'age': age, 'drug': drug, 'recovery': recovery}) # Step 1: Define the causal model as a DAG model = CausalModel( data=df, treatment="drug", outcome="recovery", common_causes=["age"] # age is a confounder ) # Step 2: Identify the causal effect identified_estimand = model.identify_effect(proceed_when_unidentifiable=True) print(identified_estimand) # Step 3: Estimate the causal effect (controlling for age via backdoor adjustment) estimate = model.estimate_effect( identified_estimand, method_name="backdoor.linear_regression", control_value=0, treatment_value=1, ) print(f"Estimated ATE: {estimate.value:.3f}") # Should recover ~0.5 (the true causal effect) # Naive regression ignoring confounding: naive_corr = df[df.drug==1]['recovery'].mean() - df[df.drug==0]['recovery'].mean() print(f"Naive (biased) correlation: {naive_corr:.3f}") # Will be biased because older people receive drug more but recover less # Step 4: Refute the estimate (robustness checks) refutation = model.refute_estimate(estimate, method_name="random_common_cause") print(refutation) # Good estimate: adding random confounder shouldn't change result </syntaxhighlight> ; Causal inference methods by scenario : '''RCT available''' β Compute difference in means (no adjustment needed β randomization handles confounding) : '''Observational, confounders known''' β Propensity score matching, IPW, doubly-robust estimators : '''Observational, confounders unknown''' β Instrumental variables (IV), regression discontinuity : '''Time series, sequential treatments''' β G-computation, marginal structural models : '''Causal structure unknown''' β Causal discovery: PC algorithm, FCI, LiNGAM, NOTEARS : '''Heterogeneous effects''' β Causal forests, meta-learners (S, T, X-learner) </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information