luk*_*keg 19 r match matching standard-deviation
因此,请遵循匹配包中的示例,特别是GenMatch示例.这是从前一个问题继续
按照中的例子 GenMatch
library(Matching)
data(lalonde)
attach(lalonde)
X = cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74)
BalanceMat <- cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74,
I(re74*re75))
genout <- GenMatch(Tr=treat, X=X, BalanceMatrix=BalanceMat, estimand="ATE", M=1,
pop.size=16, max.generations=10, wait.generations=1)
genout$matches
genout$ecaliper
Y=re78/1000
mout <- Match(Y=Y, Tr=treat, X=X, Weight.matrix=genout)
summary(mout)
Run Code Online (Sandbox Code Playgroud)
我们看到185个治疗观察与270个非治疗观察配对.
我们可以通过以下方式生成一个表格,其中包含左侧的治疗病例及其年龄,以及右侧的对照病例和年龄:
pairs <- data.frame(mout$index.treated, lalonde$age[mout$index.treated], mout$index.control, lalonde$age[mout$index.control])
Run Code Online (Sandbox Code Playgroud)
现在,关于Weight.Matrix生成的文献GenMatch是非常神秘的,并没有解释这些值代表什么.我在这里有一个未解决的问题.现在假设我们想要放宽匹配,以便在年龄标准上进行更灵活的配对.
我们看到这sd(lalonde$age)为我们的数据提供了7年的SD.
所以我想要Weight.matrix解释这一点.我想对age变量使用1 SD的限制,因此返回比原始185-270更多的对.
我的猜测是生成第二个GenMatch函数,然后继续我的代码.所以我使用:
genout <- GenMatch(Tr=treat, X=X, BalanceMatrix=BalanceMat, estimand="ATE",
pop.size=1000, max.generations=10, wait.generations=1,
caliper=c(2,1,1,1,1,1,1,1,1,1))
Run Code Online (Sandbox Code Playgroud)
但这并没有显着增加我返回的对数.
我出错的任何提示或解决方案
正如尼克·肯尼迪所描述的:
summary(as.logical(lalonde$treat))
Mode FALSE TRUE NA's
logical 260 185 0
Run Code Online (Sandbox Code Playgroud)
GenMatch 只会匹配M每个治疗病例的时间。它可能会丢弃已处理的案例,并且通常会丢弃控制案例,因为许多案例不匹配,但它不能凭空生成新的已处理案例:这就是多重插补的用途;-)
如果您的意思是,为每个处理的案例生成更多匹配项,这是通过M参数实现的,但是需要谨慎,特别是当控件的数量非常接近处理的案例的数量时(如数据中所示)lalonde,因为它已经找到了最佳的匹配,并且添加额外的匹配不太可能改善问题,而且常常会使问题变得更糟。当控制数量>>处理数量时这是最好的。
M > 1如果您愿意的话,您可以从输出数据中重建每对“匹配” ,这将给出大于治疗组中 185 行的行数,但当然会有重复项。