ngreifer / cobalt

Covariate Balance Tables and Plots - An R package for assessing covariate balance
https://ngreifer.github.io/cobalt/
73 stars 12 forks source link

bal.tab not accepting numeric factor levels with mnps #35

Closed KZARCA closed 4 years ago

KZARCA commented 4 years ago

Hi, from the twang example, if treat has character levels, it works:

library(twang)
data(AOD)
mnps.AOD <- mnps(treat ~ illact + crimjust + subprob + subdep + white,
                 data = AOD, 
                 estimand = "ATE", 
                 verbose = FALSE, 
                 stop.method = c("es.mean"), 
                 n.trees = 3000)
bal.tab(mnps.AOD)

If, however, you add: levels(AOD$treat) <- 1:3 at the beginning, you get

Error in `[.data.frame`(do.call("cbind", unname(lapply(bal.tab.multi.list,  : 
  undefined columns selected 
ngreifer commented 4 years ago

Thanks, someone else reported that bug and it’ll be fixed in the next release. If a multi-category treatment has names that are numbers, it won’t work. Use other names to make it work correctly for now.