> summary(lm(data=data,y~d))
Call:
lm(formula = y ~ d, data = data)
Residuals:
Min 1Q Median 3Q Max
-12.3599-2.72840.03752.879111.4583
Coefficients:
Estimate Std. Error t value Pr(>|t|)(Intercept)0.82420.16994.8521.42e-06***
d 11.81070.238449.549<2e-16***---
Signif. codes:0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error:3.768 on 998 degrees of freedom
Multiple R-squared:0.711, Adjusted R-squared:0.7107F-statistic:2455 on 1 and 998 DF, p-value:<2.2e-16
介入効果の推定値は11.8107でした.真の効果は3ですから,過大推定になっています.
回帰ではなく,条件付き期待値の差をとっても同じ結果を得ます.
mean(y[d==1])-mean(y[d==0])
傾向スコアマッチング
傾向スコアはすでに計算済みですから,それをつかってマッチングデータを作り,ATEを推定します.
> matched.data <- Match(Y = data$y, Tr=data$d, X =p,estimand="ATE")> summary(matched.data)#Matched number of observations............... 500
Estimate... 3.4254
AI SE...... 0.23556T-stat..... 14.541
p.val...... <2.22e-16
Original number of observations.............. 1000
Original number of treated obs............... 508
Matched number of observations............... 1000
Matched number of observations (unweighted). 1152
matched.data <- Match(Y = y, Tr=d, X =p.predict,estimand="ATE")
summary(matched.data)
Estimate... 7.2681
AI SE...... 0.10906T-stat..... 66.645
p.val...... <2.22e-16
Original number of observations.............. 3000
Original number of treated obs............... 1509
Matched number of observations............... 3000
Matched number of observations (unweighted). 7892
matched.data2 <- Match(Y = y, Tr=d, X =p.predict2,estimand="ATE")
summary(matched.data2)
Estimate... 3.4448
AI SE...... 0.1594T-stat..... 21.611
p.val...... <2.22e-16
Original number of observations.............. 3000
Original number of treated obs............... 1509
Matched number of observations............... 3000
Matched number of observations (unweighted). 4921
n <-3000;# sample size
tau <-3;# 真の介入効果
x1 <- runif(n,-5,5)# 共変量
x2 <- runif(n,-5,5)# 共変量
y0 <-x1+x2#潜在的結果y0, x1,x2の影響を受ける
y1 <- y0+tau #潜在的結果y1
p <-1/(1+exp(-x1-x2))# make probabilities by logistic function
d <- rbinom(n,size=1,p)# treatment with bias
y <- c()for(i in1:n){# 観測値yの生成if(d[i]==1){y[i]<- y1[i]}else{y[i]<- y0[i]}}
dat <-data.frame(d,x1,x2,y)
> IPW_result
# A tibble: 2 x 5
term estimate std.error statistic p.value
<chr><dbl><dbl><dbl><dbl>1(Intercept)-2.160.0679-31.94.56e-1922 d 7.450.095977.70.> IPW_result2
# A tibble: 2 x 5
term estimate std.error statistic p.value
<chr><dbl><dbl><dbl><dbl>1(Intercept)-0.2690.0923-2.923.58e-32 d 4.020.13430.16.63e-174