도구변수를 활용하여 인과효과를 추정하기
Simple Example of DoWhy using Instrumental Variables
Loading the dataset
import numpy as np
import pandas as pd
import patsy as ps
from statsmodels.sandbox.regression.gmm import IV2SLS
import os, sys
from dowhy import CausalModeln_points = 10000 # 데이터 개수
education_abilty = 1 # discrete
education_voucher = 2 # discrete
income_abilty = 2 # discrete
income_education = 4 # education 과 곱해지는 계수로, 찾고자 하는 인과효과 estimate 의 정답지
# confounder (unobserved)
ability = np.random.normal(0, 3, size=n_points)
# instrument
voucher = np.random.normal(2, 1, size=n_points)
# treatment
education = np.random.normal(5, 1, size=n_points) + education_abilty * ability +\
education_voucher * voucher
# outcome
income = np.random.normal(10, 3, size=n_points) +\
income_abilty * ability + income_education * educationeducation
income
voucher
Using DoWhy to estimate the causal effect of education on future income
step 1 : model

step 2 : identify
Step 3: Estimate
step 4 : refute
2SLS와 비교
Dep. Variable:
income
R-squared:
0.890
coef
std err
t
P>|t|
[0.025
0.975]
Omnibus:
3.175
Durbin-Watson:
1.953
Last updated