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,350
  • 1
  • 8
  • 14
Mohamed Rahouma
  • 595
  • 3
  • 13

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
  • 1,737
  • 8
  • 15