繁体   English   中英

R中马氏距离最近邻匹配的子分类

[英]Subclassification with Mahalanobis distance nearest neighbor matching in R

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

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

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
  )

同样,我要寻找的是 output 对每对处理和控制都有一个 ID,就像使用其他匹配方法(例如,“exact”或“cem”)报告的子类一样。

在这种情况下,您正在寻找 output 的属性: output 是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,在这种情况下,马汉洛比斯距离,但是警告消息Warning message: No subclassification with pure Mahalanobis distance告诉您,为此方法其他最优参数可能是更好的选择。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM