cobalt represents a processed treatment variable as an object of class treat, carrying attributes that record what kind of treatment it is and what its groups are called. Every bal.tab() method builds one, and every balance computation reads it rather than re-deriving the same facts from the values.
The attributes are
treat.typeone of
"binary","multinomial","continuous", or"censoring". This is what decides which balance statistics apply and how the treatment is compared.treat.namethe name the treatment was given, if it had one.
treat_namesfor a binary treatment, the display names of the two groups, named
controlandtreated; for a multi-category treatment, one name per level; for a censoring indicator,UncensoredandCensored.NULLfor a continuous treatment.treat_valsthe values in the data that those names correspond to.
group_labelshow the treatment's groups are labeled in the column names of a balance table.
c("0", "1")for a binary treatment, which is cobalt's positional convention (M.0is the control group's mean); otherwise whatever names the groups have.
[ preserves all of them, so a subset of a treat is still a treat.
.cens() is the only way to build one directly; it returns a censoring indicator. WeightIt::.cens() returns an object with the same class and a compatible treat.type, so an indicator tagged by either package is accepted here.
The class is shared, so carrying it means only "this is a treatment", not "this carries the attributes above": WeightIt tags its own treatments with it and supplies treat.type alone, and even cobalt's .cens() has no group names until the treatment is processed. Anything that reads treat_names or treat_vals therefore has to check for them rather than for the class, and process the treatment when they are absent.
