ngreifer / cobalt

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

MatchIt summary works, but fails in bal.tab: non-numeric argument #53

Closed ghost closed 2 years ago

ghost commented 3 years ago

I created a matchit object setting distance="mahalanobis" and exact=~specialty + event_month, where specialty is of character type (only two possible values) and event_month of date type.

Calling summary on the matchit object correctly returns the balanace statistics: image The event_month variable was implicitly converted to numeric, while specialty seems to be converted into 0 or 1s for each possible value. For both variables, summary.matchit is able to compute a std. mean difference.

However, calling bal.tab on the matchit object results in the error: image

Any advice on how to handle this error?

lucasxteixeira commented 3 years ago

I'm having the exact same error. I have just tested the previous version on CRAN (4.2.4) and it works.

ngreifer commented 3 years ago

I'm so sorry you are getting this error! I'm not able to reproduce this error using dates or character variables, so I'm not sure what the problem is. @lucasxteixeira, when you say "it works", do you mean it functions correctly, or you are able to reproduce the error in your dataset? Would you please show me the exact code you are running? Would you be willing to share your data? If not, could you run summary() on the relevant variables? Thanks!

lucasxteixeira commented 2 years ago

@ngreifer I found the issue, and it is pretty simple. The bal.tab probably uses a separate function that is imported when the cobalt package is loaded. So, when we use the function though the namespace without loading explicitly the errors appears:

lalonde <- read.csv("lalonde.csv")
w.out <- WeightIt::weightit(treat ~ age + educ + race + married + nodegree + re74 + re75, data = lalonde)
cobalt::bal.tab(w.out, thresholds = c(m = 0.1), un = TRUE)
ngreifer commented 2 years ago

@lucasxteixeira thank you so much for finding that out. With that knowledge, I was able to fix the issue, and I should have an updated version soon.