ngreifer / cobalt

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

Add # of units discarded in bal.tab()$Observations when using subclassification with discard #59

Open sky0502 opened 2 years ago

sky0502 commented 2 years ago

Hi, I have a suggestion to add # of units discarded in bal.tab()$Observations when using subclassification with discard. For example,

library(MatchIt)
library(cobalt)
data("lalonde")
m_out <- matchit(treat ~ age + educ + race + married + nodegree, 
                 data = lalonde, method = "subclass", distance = "glm", discard = "both")
m_summary <- bal.tab(m_out)
m_summary$Observations

Currently it returns

          1  2  3  4  5  6 All
Control 297 21 24 15  9 14 429
Treated  31 31 30 31 31 30 185
Total   328 52 54 46 40 44 614

Add a column of "discarded" so that the numbers add up to "All".

          1  2  3  4  5  6 Discarded All
Control 297 21 24 15  9 14       49  429
Treated  31 31 30 31 31 30        1  185
Total   328 52 54 46 40 44       50  614
ngreifer commented 2 years ago

Great suggestion, thanks!