在 R 中使用马哈拉诺比斯距离最近邻匹配进行子分类

Subclassification with Mahalanobis distance nearest neighbor matching in R

我正在使用 MatchIt 包来实现与 Mahalonobis 距离的最近邻匹配。在匹配阶段之后,如何让它报告哪个对照观察与每个治疗观察相匹配?

以下代码不起作用并抛出警告“没有纯马氏距离的子分类”。

library("MatchIt")

data("lalonde")

lalonde_matchit_nn <-
  matchit(
    treat ~ age + educ + black + hispan + nodegree + married + re74 + re75,
    baseline.group = 1,
    data = lalonde,
    method = "nearest",
    distance = "mahalanobis",
    subclass = T
  )

同样,我寻找的是输出具有每对治疗和控制的 ID,就像使用其他匹配方法(例如“exact”或“cem”)报告的子类一样。

在这种情况下,您正在寻找输出的属性:输出是 lalonde_matchit_nn,属性是 nnmatch.matrix

smry<-lalonde_matchit_nn$nn #A basic summary table of matched data (e.g., the number of matched units)

#represent the names of the treatment units, which
#come from the data frame specified in data. Each column stores the name(s)
#of the control unit(s) matched to the treatment unit of that row. F
matchedPool<-lalonde_matchit_nn$match.matrix

现在,如果您查看上面代码中的 smry 和匹配池:

smry
          Control Treated
All           429     185
Matched       185     185
Unmatched     244       0
Discarded       0       0

head(matchedPool)

     1        
NSW1 "PSID375"
NSW2 "PSID341"
NSW3 "PSID361"
NSW4 "PSID345"
NSW5 "PSID172"
NSW6 "PSID237"

smry 告诉每个类型的人口,匹配池为您提供符合您的最佳标准的 ID,在本例中为 Mahanlobis 距离,但是警告消息 Warning message: No subclassification with pure Mahalanobis distance 告诉您对于此方法其他优化参数可以是更好的选择。

有关更多详细信息,最好参考包文档, https://cran.r-project.org/web/packages/MatchIt/MatchIt.pdf