【问题标题】:MatchIt Package: Combining "nearest neighbor" matching and "exact" matchingMatchIt 包:结合“最近邻”匹配和“精确”匹配
【发布时间】:2016-09-17 17:46:20
【问题描述】:

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

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

test = matchit(treat ~ age + educ + married, method = "nearest", 
                                       exact  = c(married), data = lalonde)

我希望这段代码会对变量married(具有01 的二进制变量)执行精确匹配,然后对模型中的所有其他变量执行“最近”匹配。

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

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

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

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

【问题讨论】:

    标签: r matching exact-match


    【解决方案1】:

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

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

    【讨论】:

    • 我猜 matchit 函数中存在一些错误。它总是不能用正确的代码给出正确的结果。很遗憾,我无法分享我的数据集。
    猜你喜欢
    • 2017-07-25
    • 2018-06-09
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多