Closed eipi10 closed 9 months ago
I definitely need to correct that error! I think you need to supply addl
as a formula, not a string. Can you try that?
Maybe I'm not understanding what addl
is expecting. I've tried the following and they all fail with the same error:
bal.tab(m.out, addl= treat ~ work.for.pay)
bal.tab(m.out, addl= ~ work.for.pay)
bal.tab(m.out, addl= "treat ~ work.for.pay")
bal.tab(m.out, addl= "~ work.for.pay")
Yeah, this is a bug then. It expects the second option btw. Thanks for letting me know about it and sorry for the confusion. You can always use the formula interface to bal.tab()
, which hopefully is less buggy:
bal.tab(treat ~ gpa + gender + eth + mother.ed + units.earned + work.for.pay,
data = mdat, weights = m.out)
Actually, I just re-read the help for bal.tab.matchit
and it does say that for addl
one can provide a "character vector containing their names", so it seems like it should also work with the character string.
Yup, it's a bug.
I'm both pleased and mortified to report that this is not a cobalt
bug. I was accidentally removing the relevant additional columns from the data frame I passed to matchit
. But then because I had removed a few rows of data for the "Nonbinary" students (as we discussed in my previous issue), when I tried using an external data frame, it didn't have the correct number of rows. This was all going on in a function I wrote that obviously needs a few more tests to make sure it's doing what I think it's doing. So, it was operator error. Sorry to have wasted your time.
I'm getting an error that occurs with my real data, but that I can't reproduce in a small example. I'm running
bal.tab
on amatchit
object. It works fine if I just dobal.tab(m.out)
, which produces the expected balance table. But if I use theaddl
argument to add an additional variable or variables that were not included in the matching, I get an error. The workflow looks like this:work.for.pay
is a column inmdat
, the data provided tomatchit
, and it has no missing values. I've tried with several other variables not included in the matching formula, some categorical, some numeric, some with missing values, and some with complete cases, but I always get the same error. Do you have any ideas what's causing this and how I can avoid the error?