R:使用 MatchIt 进行倾向得分匹配。如何使用replace = TRUE查找匹配观察值的数量?

标签 r matching nearest-neighbor propensity-score-matching

请考虑以下事项:

我正在将数据与 R 中的 MatchIt 包进行匹配。我的控件少于处理的控件,并使用选项 replace = TRUE。根据manual ,权重告诉我们匹配控件的频率。

来自手册:

"For matching with replacement, use replace = TRUE. After matching with replacement, the weights can be used to reflect the frequency with which each control unit was matched."

但是,我不明白为什么权重可以有小数以及这如何反射(reflect)频率。

例如,我在手册中的示例中添加了 replace == TRUE(参见第 18 页):

library("dplyr")
library("MatchIt")

m.out1 <- matchit(treat ~ re74 + re75 + age + educ, data = lalonde,
 method = "nearest", distance = "logit", replace = T)

tail(match.data(m.out1), 15)
#>         treat age educ black hispan married nodegree re74 re75      re78
#> PSID388     0  19   11     1      0       0        1    0    0 16485.520
#> PSID390     0  48   13     0      0       1        0    0    0     0.000
#> PSID392     0  17   10     1      0       0        1    0    0     0.000
#> PSID393     0  38   12     0      0       1        0    0    0 18756.780
#> PSID396     0  48   14     0      0       1        0    0    0  7236.427
#> PSID398     0  17    8     1      0       0        1    0    0  4520.366
#> PSID400     0  37    8     1      0       0        1    0    0   648.722
#> PSID401     0  17   10     1      0       0        1    0    0  1053.619
#> PSID407     0  23   12     0      0       0        0    0    0  3902.676
#> PSID409     0  17   10     0      0       0        1    0    0 14942.770
#> PSID411     0  18   10     1      0       0        1    0    0  5306.516
#> PSID413     0  17   10     0      0       1        1    0    0  3859.822
#> PSID419     0  51    4     1      0       0        1    0    0     0.000
#> PSID423     0  27   10     1      0       0        1    0    0  7543.794
#> PSID425     0  18   11     0      0       0        1    0    0 10150.500
#>          distance weights
#> PSID388 0.4067545     0.6
#> PSID390 0.4042321     1.2
#> PSID392 0.3974677     0.6
#> PSID393 0.4016920     4.2
#> PSID396 0.4152715     0.6
#> PSID398 0.3758217     1.8
#> PSID400 0.3595084     0.6
#> PSID401 0.3974677     1.2
#> PSID407 0.4144044     1.8
#> PSID409 0.3974677     0.6
#> PSID411 0.3966277     1.2
#> PSID413 0.3974677     1.2
#> PSID419 0.3080590     0.6
#> PSID423 0.3890954     1.2
#> PSID425 0.4076015     1.2

对于控件“PSID393”,权重为 4.276。因此,我假设该控件匹配了 4 或 5 次(四舍五入后)。

但是,我们也可以查看 match.matrix 来一一查看匹配的处理和控件。过滤“PSID393”,我们看到该控件实际上已经匹配了7次:

m.out1$match.matrix %>% data.frame() %>% filter(X1 == "PSID393")


#>        X1
#> 1 PSID393
#> 2 PSID393
#> 3 PSID393
#> 4 PSID393
#> 5 PSID393
#> 6 PSID393
#> 7 PSID393

reprex package 于 2019-05-06 创建(v0.2.1)

如何正确解释这两个输出?

最佳答案

权重经过缩放,以便它们总和为对照组中唯一匹配观察值的数量。使用您的示例数据,请注意,权重总和等于观测值的数量,平均权重为 1。此外,最常用观测值的权重是最少使用观测值的七倍):

match.data(m.out1) %>%
  group_by(treat) %>% 
  summarise(min.weight=min(weights),
            max.weight=max(weights),
            mean.weight=mean(weights),
            sum.weights=sum(weights),
            n=n(),
            max.match.ratio=max.weight/min.weight)
  treat min.weight max.weight mean.weight sum.weights     n max.match.ratio
1     0      0.605       4.24           1         112   112               7
2     1      1           1              1         185   185               1

要查看权重的分布,我们可以这样做:

match.data(m.out1) %>% 
  group_by(treat, weights) %>% 
  tally %>% 
  group_by(treat) %>% 
  mutate(weight.ratio = weights/min(weights))
  treat weights     n weight.ratio
1     0   0.605    74            1
2     0   1.21     19            2
3     0   1.82     10            3
4     0   2.42      6            4
5     0   3.63      2            6
6     0   4.24      1            7
7     1   1       185            1

the MatchIt vignette末尾有常见问题解答。第 5.3 条“权重的创建精确度如何?”指出“控制组权重按比例缩放以求和到唯一匹配的控制组的数量 单位。”

关于R:使用 MatchIt 进行倾向得分匹配。如何使用replace = TRUE查找匹配观察值的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56009013/

相关文章:

python - python 中的 Stroop 测试无法正常工作。

Java——最高效的匹配方法

python - 使用加权距离度量的 Scikit-learn 最近邻搜索

algorithm - 如何在 O(n) 时间内找到 n 个不同数字的中位数的 k 个最近邻居?

r - 如何使用引用类在 R 的父类中设置字段?

r - 如何删除 .png 周围奇怪的白边(用 r、ggplot 绘制)?

r - 在 R 中将数组列表转换为数组数组(保留子数组的形状)

r - 在包检查 R 2.14.0 期间使用带有小插图的 inst/extdata

mysql - Rails : A way to check for duplicate item in DB? 联盟数据源

python - 使用 shapefile 多边形查找一阶邻居