我试图用R中的MatchIt包进行PSM分析,对某些变量使用“精确匹配”,对同一数据集中的其他变量使用“最近邻居”方法
为了解决这个问题,我将使用示例dataset lalonde。
test = matchit(treat ~ age + educ + married, method = "nearest",
exact = c(married), data = lalonde)我预期这段代码将对变量married (带有0和1的二进制变量)执行精确匹配,然后对模型中的所有其他变量执行“最近”匹配。
然而,我收到了以下警告信息:
警告消息:未包含在数据中的确切变量。完全匹配还没有完成。
查看matchit输出的摘要,只使用“最近”方法。我不知道错误在哪里,因为仅仅使用“精确”方法,函数就可以识别精确的匹配,但不能与其他匹配方法结合使用。
您知道如何将“精确”匹配和“最近邻居”匹配在同一个数据集中,或者知道我的错误在哪里吗?
发布于 2016-09-17 18:58:23
正在发生的情况是,您在包的最近邻居文件中命中了这个循环:
## Now for exact matching within nearest neighbor
## exact should not equal T for this type of matching--that would get sent to matchit2exact
if (!is.null(exact)){
if(!sum(exact%in%names(data))==length(exact)) {
warning("Exact variables not contained in data. Exact matching not done.",call.=FALSE)
exact=NULL
}
else {
ww <- exact%in%dimnames(X)[[2]]
nw <- length(exact)
exact <- data[,exact,drop=F]
if(sum(ww)!=nw){
X <- cbind(X,exact[!ww])
}
}
}我相信这要归功于你指定married的方式。
以下版本不会引发错误:
test = matchit(treat ~ age + educ + married, method = "nearest",
exact = "married", data = lalonde)https://stackoverflow.com/questions/39549935
复制相似问题