mnps function of R twang package shows warning errors for Absolute Standardized Difference plot

597 Views Asked by At

I have a dataset with 3465 observation and 5 variables as follows (named: dataset)

Variables

$ Treat --> factor(3 level: "1", "2", "3")
$ Age --> integer(eg. 24,54,etc.)
$ Mortality --> integer(0=no,1= yes)
$ LDL --> integer(eg. 200,120,143, etc.)
$ Smoking --> integer(0=no, 1= yes)

I used mnps function in twang package to weight my observations according to treat

mnps code

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

``` ### Plot ###

Then I used plot function to assess the balance of the data after weighting. There was no problem for plots 1 and 2, (balanced of treatment per iterations, and propensity score distribution of treatments.)

Plot code

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

But when i wanted to run plot 3 for Absolute Standardized difference, it made an error with some warnings and an empty plot:

Warning Error

plot(mnps.dataset, plots = 3)

Warning messages:

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: ...

___________________

Note : "..." means repeated previous error

Image of empty plot generated by mnps plot=3

1

There are 1 best solutions below

3
On BEST ANSWER

This is a bug in twang (I was able to replicate it on my own dataset). There isn't anything you can do about it.

You can instead use the cobalt package, which facilitates balance checking and is compatible with objects from twang. A plot that conveys the same information as the type 3 plot is a Love plot, which can be called using love.plot() in cobalt.

If you run love.plot(mnps.dataset, which.treat = .all) you can see standardized mean differences for all pairwise comparisons. See the section in the cobalt vignette on multi-category treatments for more information on how to use it.