Description Usage Arguments Details Value Author(s) See Also Examples
Generates balance statistics for unadjusted, matched, weighted, or stratified data using either a data.frame
or formula interface.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  ## S3 method for class 'data.frame'
bal.tab(x,
treat,
data = NULL,
weights = NULL,
subclass = NULL,
match.strata = NULL,
method,
stats,
int = FALSE,
poly = 1,
distance = NULL,
addl = NULL,
continuous,
binary,
s.d.denom,
thresholds = NULL,
cluster = NULL,
imp = NULL,
pairwise = TRUE,
focal = NULL,
s.weights = NULL,
estimand = NULL,
abs = FALSE,
subset = NULL,
quick = TRUE,
...)
## S3 method for class 'formula'
bal.tab(x,
data = NULL,
...)

x 
either a 
treat 
Either a vector containing treatment status values for each unit or a string containing the name of the treatment variable in 
data 
Optional; a 
weights 
Optional; a vector, list, or 
subclass 
Optional; either a vector containing subclass membership for each unit or a string containing the name of the subclass variable in 
match.strata 
Optional; either a vector containing matching stratum membership for each unit or a string containing the name of the matching stratum variable in 
method 
A character vector containing the method of adjustment, if any. If 
stats 

int 

poly 

distance 
an optional formula or data frame containing distance values (e.g., propensity scores) or a character vector containing their names. If a formula or variable names are specified, 
addl 
an optional formula or data frame containing additional covariates for which to present balance or a character vector containing their names. If a formula or variable names are specified, 
continuous 
whether mean differences for continuous variables should be standardized ( 
binary 
whether mean differences for binary variables (i.e., difference in proportion) should be standardized ( 
s.d.denom 

thresholds 
a named vector of balance thresholds, where the name corresponds to the statistic (i.e., in 
cluster 
either a vector containing cluster membership for each unit or a string containing the name of the cluster membership variable in 
imp 
either a vector containing imputation indices for each unit or a string containing the name of the imputation index variable in 
pairwise 
whether balance should be computed for pairs of treatments or for each treatment against all groups combined. See 
focal 
The name of the focal treatment when multiple categorical treatments are used. See 
s.weights 
Optional; either a vector containing sampling weights for each unit or a string containing the name of the sampling weight variable in 
estimand 

abs 

subset 
A 
quick 

... 
For 
bal.tab.data.frame()
generates a list of balance summaries for the covariates and treatment status values given. bal.tab.formula()
does the same but uses a formula interface instead. When the formula interface is used, the formula and data are reshaped into a treatment vector and data.frame
of covariates and then simply passed through the data.frame
method.
The argument to match.strata
corresponds to a factor vector containing the name or index of each pair/stratum for units conditioned through matching, for example, using the optmatch package. If more than one of weights
, subclass
, or match.strata
are specified, bal.tab()
will attempt to figure out which one to apply. Currently only one of these can be applied ta a time. bal.tab()
behaves differently depending on whether subclasses are used in conditioning or not. If they are used, bal.tab()
creates balance statistics for each subclass and for the sample in aggregate. See bal.tab.subclass
for more information.
All balance statistics are calculated whether they are displayed by print
or not, unless quick = TRUE
. The threshold
argument controls whether extra columns should be inserted into the Balance table describing whether the balance statistics in question exceeded or were within the threshold. Including these thresholds also creates summary tables tallying the number of variables that exceeded and were within the threshold and displaying the variables with the greatest imbalance on that balance measure. When subclassification is used, the extra threshold columns are placed within the balance tables for each subclass as well as in the aggregate balance table, and the summary tables display balance for each subclass.
The inputs (if any) to covs
and data
must be a data.frame
; if more than one variable is included, this is straightforward (i.e., because data[,c("v1", "v2")]
is already a data.frame
), but if only one variable is used with the matrix subsetting syntax (e.g., data[,"v1"]
), R will coerce it to a vector, thus making it unfit for input. To avoid this, make sure to use the list subsetting syntax (e.g., data["v1"]
) if only one variable is to be added (this can also be used for multiple variables and is good practice in general). Again, when more than one variable is included, the input is generally already a data.frame
and nothing needs to be done.
Multiple sets of weights can be supplied simultaneously by entering a data.frame
or a character vector containing the names of weight variables found in data
or a list of weights vectors or names. The arguments to method
, s.d.denom
, and estimand
, if any, must be either the same length as the number of sets of weights or of length one, where the sole entry is applied to all sets. When standardized differences are computed for the unadjusted group, they are done using the first entry to s.d.denom
or estimand
. When only one set of weights is supplied, the output for the adjusted group will simply be called "Adj"
, but otherwise will be named after each corresponding set of weights. Specifying multiple sets of weights will also add components to other output of bal.tab()
.
For point treatments, if clusters and imputations are not specified, an object of class "bal.tab"
containing balance summaries for the specified treatment and covariates. See \funbal.tab for details.
If imputations are specified, an object of class "bal.tab.imp"
containing balance summaries for each imputation and a summary of balance across imputations. See bal.tab.imp
for details.
If multiple categorical treatments are used, an object of class "bal.tab.multi"
containing balance summaries for each pairwise treatment comparison. See bal.tab.multi
for details.
If clusters are specified, an object of class "bal.tab.cluster"
containing balance summaries within each cluster and a summary of balance across clusters. See bal.tab.cluster
for details.
Noah Greifer
bal.tab for output and details of calculations.
bal.tab.cluster
for more information on clustered data.
bal.tab.imp
for more information on multiply imputed data.
bal.tab.multi
for more information on multiple categorical treatments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  data("lalonde", package = "cobalt")
lalonde$p.score < glm(treat ~ age + educ + race, data = lalonde,
family = "binomial")$fitted.values
covariates < subset(lalonde, select = c(age, educ, race))
## Propensity score weighting using IPTW
lalonde$iptw.weights < ifelse(lalonde$treat==1,
1/lalonde$p.score,
1/(1lalonde$p.score))
# data frame interface:
bal.tab(covariates, treat = "treat", data = lalonde,
weights = "iptw.weights", s.d.denom = "pooled")
# Formula interface:
bal.tab(treat ~ age + educ + race, data = lalonde,
weights = "iptw.weights", s.d.denom = "pooled")
## Propensity score subclassification
lalonde$subclass < findInterval(lalonde$p.score,
quantile(lalonde$p.score,
(0:6)/6), all.inside = TRUE)
# data frame interface:
bal.tab(covariates, treat = "treat", data = lalonde,
subclass = "subclass", disp.subclass = TRUE,
s.d.denom = "pooled")
# Formula interface:
bal.tab(treat ~ age + educ + race, data = lalonde,
subclass = "subclass", disp.subclass = TRUE,
s.d.denom = "pooled")

cobalt (Version 4.2.4, Build Date: 20201105 17:30:21 UTC)
Balance Measures
Type Diff.Adj
age Contin. 0.1242
educ Contin. 0.0727
race_black Binary 0.0053
race_hispan Binary 0.0025
race_white Binary 0.0029
Effective sample sizes
Control Treated
Unadjusted 429. 185.
Adjusted 344.33 65.47
Balance Measures
Type Diff.Adj
age Contin. 0.1242
educ Contin. 0.0727
race_black Binary 0.0053
race_hispan Binary 0.0025
race_white Binary 0.0029
Effective sample sizes
Control Treated
Unadjusted 429. 185.
Adjusted 344.33 65.47
Balance by subclass
   Subclass 1   
Type Diff.Adj
age Contin. 1.2029
educ Contin. 0.2551
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 2   
Type Diff.Adj
age Contin. 0.4108
educ Contin. 0.3005
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 3   
Type Diff.Adj
age Contin. 0.1400
educ Contin. 0.0295
race_black Binary 0.0000
race_hispan Binary 0.0833
race_white Binary 0.0833
   Subclass 4   
Type Diff.Adj
age Contin. 0.2294
educ Contin. 0.4409
race_black Binary 0.3467
race_hispan Binary 0.3467
race_white Binary 0.0000
   Subclass 5   
Type Diff.Adj
age Contin. 0.4675
educ Contin. 0.3427
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 6   
Type Diff.Adj
age Contin. 0.1293
educ Contin. 0.0838
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
Balance measures across subclasses
Type Diff.Adj
age Contin. 0.0193
educ Contin. 0.0184
race_black Binary 0.0576
race_hispan Binary 0.0714
race_white Binary 0.0138
Sample sizes by subclass
1 2 3 4 5 6 All
Control 100 93 96 73 24 43 429
Treated 3 9 6 29 78 60 185
Total 103 102 102 102 102 103 614
Balance by subclass
   Subclass 1   
Type Diff.Adj
age Contin. 1.2029
educ Contin. 0.2551
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 2   
Type Diff.Adj
age Contin. 0.4108
educ Contin. 0.3005
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 3   
Type Diff.Adj
age Contin. 0.1400
educ Contin. 0.0295
race_black Binary 0.0000
race_hispan Binary 0.0833
race_white Binary 0.0833
   Subclass 4   
Type Diff.Adj
age Contin. 0.2294
educ Contin. 0.4409
race_black Binary 0.3467
race_hispan Binary 0.3467
race_white Binary 0.0000
   Subclass 5   
Type Diff.Adj
age Contin. 0.4675
educ Contin. 0.3427
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
   Subclass 6   
Type Diff.Adj
age Contin. 0.1293
educ Contin. 0.0838
race_black Binary 0.0000
race_hispan Binary 0.0000
race_white Binary 0.0000
Balance measures across subclasses
Type Diff.Adj
age Contin. 0.0193
educ Contin. 0.0184
race_black Binary 0.0576
race_hispan Binary 0.0714
race_white Binary 0.0138
Sample sizes by subclass
1 2 3 4 5 6 All
Control 100 93 96 73 24 43 429
Treated 3 9 6 29 78 60 185
Total 103 102 102 102 102 103 614
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.