R MatchIt软件包:合并“;“最近邻居”;配对及「;确切的;匹配

R MatchIt软件包:合并“;“最近邻居”;配对及「;确切的;匹配,r,matching,exact-match,R,Matching,Exact Match,我试图用R中的MatchIt包进行PSM分析,对某些变量使用“精确匹配”,对同一数据集中的其他变量使用“最近邻”方法 对于这个问题,我将使用示例数据集lalonde test = matchit(treat ~ age + educ + married, method = "nearest", exact = c(married), data = lalonde) 我希望此代码将对变量married(二进制变量0

我试图用R中的
MatchIt
包进行PSM分析,对某些变量使用“精确匹配”,对同一数据集中的其他变量使用“最近邻”方法

对于这个问题,我将使用示例数据集
lalonde

test = matchit(treat ~ age + educ + married, method = "nearest", 
                                       exact  = c(married), data = lalonde)
我希望此代码将对变量
married
(二进制变量
0
1
)执行精确匹配,然后对模型中的所有其他变量执行“最近”匹配

但是,我收到了以下警告信息:

警告消息:数据中不包含确切的变量。精确匹配 没有完成

查看
matchit
输出的摘要,只使用了“最近的”方法。我不知道错误在哪里,因为只使用“精确”方法,函数识别精确匹配,但不与其他匹配方法结合使用


你知道如何在同一个数据集中结合“精确”匹配和“最近邻”匹配的方法吗?或者知道我的错误在哪里

发生的情况是,您在包的最近邻文件中遇到了这个循环:

  ## 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])
    }
   }
  }

我猜matchit函数中有一些bug。它总是不能用正确的代码给出正确的结果。不幸的是,我无法共享我的数据集。
test = matchit(treat ~ age + educ + married, method = "nearest", 
               exact  = "married", data = lalonde)