2

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

Behnam Hedayat
  • 837
  • 4
  • 18

1 Answers1

1

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.

Noah
  • 3,437
  • 1
  • 11
  • 27
  • 2
    Yes. I just wanted to know that it's a bug in twang package. I had used "your" excellent cobalt package instead after and it worked very well on my dataset. Many thanks. – Behnam Hedayat Feb 05 '21 at 14:04
  • 2
    I also wanted to know that is it possible to perform PS matching for studies with multiple treatments (like my dataset) in Cobalt or other R packages , something like binomial PS matching with nearest neighbor method as we do in MatchIt package, Which produce matched dataset instead of weighting for analysis. – Behnam Hedayat Feb 05 '21 at 14:13
  • 1
    Glad you found `cobalt` helpful. I don't know of a good package for multi-category treatment matching. It's something I hope to add to `MatchIt` in the future. – Noah Feb 05 '21 at 17:54