bal.plot.Rd
Generates density plots, bar graphs, or scatterplots displaying distributional balance between treatment and covariates using ggplot2.
bal.plot(x, var.name, ..., which, which.sub = NULL, cluster = NULL, which.cluster = NULL, imp = NULL, which.imp = NULL, which.treat = NULL, which.time = NULL, mirror = FALSE, type = "density", colors = NULL, grid = FALSE, sample.names, position = "right", facet.formula = NULL, disp.means = getOption("cobalt_disp.means", FALSE), alpha.weight = TRUE)
x  the object for which balance is to be assessed; can be any object for which there is support in 

var.name 

...  other arguments to define the variable, treatment, and weights. Some inputs are required depending on the method. See Additional Arguments. Can also be used to supply the 
which  whether to display distributional balance for the adjusted ( 
which.sub 

cluster  optional; a vector of cluster membership, or the name of a variable in an available data set passed to 
which.cluster  if clusters are used, which cluster(s) to display. Can be cluster names or numerical indices for which to display balance. Indices correspond to the alphabetical order of cluster names. If 
imp  optional; a vector of imputation indices, or the name of a variable in an available data set passed to 
which.imp  if imputations are used, which imputations(s) to display. Must be numerical indices for which to display balance. If 
which.treat  which treatment groups to display. If 
which.time  for longitudinal treatments, which time points to display. Can be treatment names or time period indices. If 
mirror 

type 

colors  a vector of colors for the plotted densities/histograms. See 'Color Specification' at 
grid 

sample.names 

position  the position of the legend. This can be any value that would be appropriate as an argument to 
facet.formula  a 
disp.means 

alpha.weight 

bal.plot()
works like bal.tab()
in that it can take a variety of types of inputs and yield the same output for each. Depending on what kind of input is given, different additional parameters are required in ...
. For details on what is required and allowed for each additional input and their defaults, see the help file for the bal.tab()
method associated with the input. The following are the required additional arguments based on each input type:
For matchit
objects: None
For weightit
objects: None
For ps
, ps.cont
, mnps
, and iptw
objects: (stop.method
; see defaults).
For Match
objects: formula
and data
or covs
and treat
.
For optmatch
objects: formula
and data
or covs
(treat
is not required).
For CBPS
objects: None
For ebalance
objects: formula
and data
or covs
and treat
.
For formula
s: data
For data.frame
s: treat
For designmatch
objects: formula
and data
or covs
and treat
.
For sbw
objects: None
For mimids
and wimids
objects: None, but an argument to which.imp
should be specified.
For other objects processed through bal.tab()
's default method, whichever arguments are required to identify treatment, variables, and a conditioning method (if any).
bal.plot()
uses ggplot()
from the ggplot2 package, and (invisibly) returns a "ggplot"
object. For categorical treatments with continuous covariates or continuous treatments with categorical covariates, density plots are created using geom_density()
, histograms are created using geom_histogram()
, and empirical CDF plots are created using geom_step()
; for categorical treatments with categorical covariates, bar graphs are created using geom_bar()
; for continuous treatments with continuous covariates, scatterplots are created using geom_point()
.
For continuous treatments with continuous covariates, four additional lines are presented for aid in balance assessment. The red line is the linear fit line. The blue line is a smoothing curve generated with ggplot2's geom_smooth()
with method = "auto"
. The horizontal black line is a horizontal reference line intercepting the (unweighted) treatment mean. The vertical black line is a reference line intercepting the (unweighted) treatment mean. Balance is indicated by the flatness of both fit lines and whether they pass through the intersection of the two black reference lines.
When multiple plots are to be displayed (i.e., when requesting subclass balance, cluster balance, or imputation balance, or when multiple sets of weights are provided or which = "both"
, or when treatment is longitudinal), the plots will be displayed in a grid using ggplot2's facet_grid()
. Subclassification cannot be used with clusters or multiply imputed data.
To change the plot and axis titles, use labs()
. Because the output is a ggplot
object, other elements can be changed using ggplot2 functions; see here for an example.
A "ggplot"
object, returned invisibly.
Noah Greifer
if (requireNamespace("MatchIt", quietly = TRUE)) { data("lalonde", package = "cobalt") #Nearest Neighbor Matching library(MatchIt) m.out < matchit(treat ~ age + educ + race + married + nodegree + re74 + re75, data = lalonde) bal.plot(m.out, "age", which = "both") bal.plot(m.out, "re74", which = "both", type = "ecdf") bal.plot(m.out, "race", which = "both") bal.plot(m.out, "distance", which = "both", mirror = TRUE, type = "histogram", colors = c("white", "black")) }; if (requireNamespace("WeightIt", quietly = TRUE)) { #PS weighting with a continuous treatment library(WeightIt) w.out < weightit(re75 ~ age + I(age^2) + educ + race + married + nodegree, data = lalonde) bal.plot(w.out, "age", which = "both") bal.plot(w.out, "married", which = "both") } #> #> Attaching package: ‘MatchIt’ #> The following object is masked _by_ ‘.GlobalEnv’: #> #> lalonde #> The following object is masked from ‘package:cobalt’: #> #> lalonde