首页 > 解决方案 > R twang 包的 mnps 函数显示绝对标准差图的警告错误

问题描述

我有一个包含 3465 个观察值和 5 个变量的数据集,如下所示(命名为:数据集)

变量

$ Treat --> factor(3 level: "1", "2", "3")
$ Age --> integer(eg. 24,54,etc.)
$ Mortality --> integer(0=no,1 = 是)
$ LDL --> 整数(例如 200,120,143 等)
$ 吸烟 --> 整数(0=否,1= 是)

我在 twang 包中使用了 mnps 函数来根据治疗来衡量我的观察结果

mnps代码

mnps.dataset <- mnps(treat ~ Age + LDL + Smoking, data = dataset, estimand = "ATE", stop.method = c("es.mean", "ks.mean"), n.trees=3000)

``` ### 绘图###

然后我使用绘图功能来评估加权后的数据平衡。图 1 和图 2 没有问题(每次迭代的治疗平衡,以及治疗的倾向得分分布。)

情节代码

plot(mnps.dataset, plots = 1) 
plot(mnps.dataset, plots = 2) 

但是当我想为绝对标准化差异运行图 3 时,它出现了一些警告和空白图的错误:

警告错误

plot(mnps.dataset, plots = 3)

警告信息:

1: In order(as.numeric(x)) : NAs introduced by coercion
2: In split(as.numeric(x) [ord], gg[ord]) : NAs introduced by coercion 
3: ...(same as error 1) 
4: ... (same as error 2)
5: ... (same as error 1) 
6: ... (same as error 2)
7: ... (same as error 1)
8: ... (same as error 2)
9: In panel.superpose(x, y, type = type, groups = groups, ... : NAs introduced by coercion 
10: ... 
11: ... 
12: ...

___________________

注意:“...”表示重复先前的错误

mnps plot=3 生成的空图的图像

标签: rplotweightingpropensity-score-matching

解决方案


这是一个错误twang(我能够在我自己的数据集上复制它)。你对此无能为力。

您可以改为使用该cobalt包,它有助于余额检查并与来自twang. 传达与类型 3 情节相同信息的情节是爱情情节,可以使用love.plot()in调用cobalt

如果您运行love.plot(mnps.dataset, which.treat = .all),您可以看到所有成对比较的标准化均值差。有关如何使用它的更多信息,请参阅cobalt小插图中关于多类别治疗的部分。


推荐阅读