繁体   English   中英

为什么 PSM 结果不同使用 R 中的 Matching 和 Matchit

[英]Why the PSM results differ using Matching and Matchit in R

我分别使用 R 包“Matching”和“Matchit”在 R 中进行了倾向得分匹配,但匹配的数量完全不同。

数据集在这里http://web.hku.hk/~bcowling/data/propensity.csvhttp://web.hku.hk/~bcowling/examples/propensity.htm example <- propensity

使用“匹配”的代码是:

m.ps <- glm(trt ~ age + risk + severity, family="binomial", data=example)

example$ps <- predict(m.ps, type="response")

PS.m <- Match(Y=example$death, Tr=example$trt, X=example$ps, M=1, caliper=0.2, replace=FALSE) summary(PS.m )

SE.........  0.041299 
T-stat.....  -2.1126 
p.val......  0.034634 

Original number of observations..............  400 
Original number of treated obs...............  192 
Matched number of observations...............  149 
Matched number of observations  (unweighted).  149 

Caliper (SDs)........................................   0.2 
Number of obs dropped by 'exact' or 'caliper'  43  

比赛次数为 149 场。

使用“MatchIt”的代码为: psm<-matchit(trt ~ age+risk+severity, data=example, method="nearest",caliper=0.2) summary(psm)

Sample Sizes:
         Control Treated
All           208     192
Matched       161     161
Unmatched      47      31
Discarded       0       0

匹配数为 161,与使用 Matching 时的 149 不同。 为什么他们不同?

两个原因:1) Matching按照数据集中的单位顺序进行匹配,而MatchIt默认情况下根据倾向得分的降序进行匹配,2) Matching默认使用非零距离容差,这意味着任何两个倾向得分差异为 0.00001 或更小的单位将被视为完全匹配,而MatchIt则没有这样的容差。

为确保MatchingMatchIt之间的结果相同,请在matchit()中设置m.order = "data"并在Match()中设置distance.tolerance = 0

PS.m <- Match(Y=example$death, Tr=example$trt, X=example$ps, M=1, caliper=0.2, replace=FALSE, ties = F,
              distance.tolerance = 0)

psm <- matchit(trt ~ age+risk+severity, data=example, method="nearest",caliper=0.2, 
               m.order = "data")

cobalt::bal.tab(psm, weights = PS.m)
#> Call
#>  matchit(formula = trt ~ age + risk + severity, data = example, 
#>     method = "nearest", m.order = "data", caliper = 0.2)
#> 
#> Balance Measures
#>              Type Diff.matchit Diff.Match
#> distance Distance       0.0043     0.0043
#> age       Contin.       0.0902     0.0902
#> risk      Contin.      -0.0348    -0.0348
#> severity  Contin.      -0.0342    -0.0342
#> 
#> Effective sample sizes
#>         Control Treated
#> All         208     192
#> matchit     149     149
#> Match       149     149

reprex 包于 2022-02-22 创建 (v2.0.1)

这里我使用了cobalt::bal.tab()来验证结果匹配的样本大小是否相同,并且余额统计信息是否相同,这表明使用这两种方法产生了相同的匹配样本。

暂无
暂无

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

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