0

I am using TWANG to match 3 treatment groups and I could produce plot 1 and 2 (shown here https://cran.r-project.org/web/packages/twang/vignettes/mnps.pdf ) but unfortunately I could not produce plot 3 that assesses absolute standardized mean differences (ASMD) before and after weighting)

Here is my code:

mnps.newtest1.ATE <- mnps(ttt_gps.3gp.Neo.Adj.dCRT ~ AGE + SEX + 
                     Race_2psW.O + CDCC_2gps01.2 + Histology_3gps +
                   TUMOR_SIZE_R + YEAR_OF_DIAGNOSIS,
                  data = testdf2, 
                  n.trees=10000,
                  interaction.depth=2,
                  shrinkage=0.01,
                   perm.test.iters=0,
                  stop.method=c("es.mean","ks.mean"),
                  estimand = "ATE",
                  verbose=F)

Warning message: In ps(formula = currFormula, data = currDat, n.trees = n.trees[i], : Optimal number of iterations is close to the specified n.trees. n.trees is likely set too small and better balance might be obtainable by setting n.trees to be larger.

plot(mnps.newtest1.ATE, plots = 3)

*****Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : length of 'dimnames' [2] not equal to array extent In addition: Warning message: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'*****

Then after googling this error, I found this solution on 1 website (length of 'dimnames' [2] not equal to array extent when using corrplot function from a matrix read from a csv file ) but it does not work yet

plot(as.matrix(mnps.newtest1.ATE), plots = 3)

Error in if (length(treatments) > 2 & x$estimand == "ATE") stop("The \"treatments\" argument must be null or have length 1 or 2.") :
argument is of length zero

Any help will be so much appreciated

Soren
  • 1,792
  • 1
  • 13
  • 16
Mohamed Rahouma
  • 1,084
  • 9
  • 20

1 Answers1

1

This is likely because you used a tibble instead of a data frame for your data (i.e., testdf2). This can happen if you use a package in the tidyverse to create your data frame, like haven. Replacing testdf2 with as.data.frame(testdf2) should solve the problem if this is the cause.

If you want a prettier display for the balance plot, I recommend using the cobalt package (which I wrote for this purpose, among others). After running library(cobalt), run love.plot(bal.tab(mnps.newtest1.ATE)), which provides a plot with the same information (see below for an example with some additional options).

enter image description here

You can set which.treat = NULL to view all pairwise difference as well.

enter image description here

Noah
  • 3,437
  • 1
  • 11
  • 27
  • Hi Noah, how would one choose specific pairwise comparisons with `which.treat` ? – Sam Pickwick Jun 08 '21 at 23:53
  • Also, I have 7 treatment arms and was trying to come up with a way to show all of the comparisons. I asked about `which.treat` above because I was thinking of doing them a couple pairs at a time but maybe something like `facet_wrap()` could work? I just don't know what to use inside the facet wrap function for this use case – Sam Pickwick Jun 08 '21 at 23:55
  • See how to use `which.treat` [here](https://ngreifer.github.io/cobalt/reference/class-bal.tab.multi.html). To wrap with `facet_wrap()`, do `love.plot(.) + facet_wrap(vars(treat), ncol = 5)`. I will tell you that displaying 21 comparisons is not the best way to display balance. Using `pairwise = FALSE` will give a more useful display. – Noah Jun 09 '21 at 00:56