Skip to contents

Plots the distribution of a specified covariate in the treated and control groups. Allows visualization of weighted or unweighted distributions using histogram or density plots.

Usage

plot_cov_bal(
  object = NULL,
  Z = NULL,
  Tr = NULL,
  wt = NULL,
  use_weights = TRUE,
  cov = NULL,
  plot_type = c("density", "hist"),
  color_treated = "red",
  color_control = "blue",
  bins = 30,
  alpha = 0.4,
  theme.size = 15,
  suppress = TRUE,
  ...
)

Arguments

object

Optional. An object of class `lbc_net`. If provided, extracts `Z`, `Tr`, and weights.

Z

A data frame or matrix of covariates. Required if `object` is not provided.

Tr

A binary numeric vector for treatment assignment (1 = treated, 0 = control). Required if `object` is not provided.

wt

A numeric vector of weights. If NULL and `object` is provided, weights are extracted from `object`. Defaults to `rep(1, length(Tr))` if not provided.

use_weights

Logical. If `TRUE` (default), applies weights to the distributions. If `FALSE`, shows the unweighted covariate distribution, even when an `lbc_net` object is provided.

cov

A character string specifying the covariate name to plot. Defaults to the first column of `Z`.

plot_type

Character string: either `"hist"` (histogram) or `"density"` (default is `"density"`).

color_treated

Color for the treated group. Default is `"red"`.

color_control

Color for the control group. Default is `"blue"`.

bins

Number of bins for the histogram (if `plot_type = "hist"`). Default is `30`.

alpha

Transparency level for fill. Default is `0.4`.

theme.size

Base font size for plot theme. Default is `15`.

suppress

Logical. If `TRUE` (default), suppresses warnings generated during plot rendering (e.g., bandwidth selection warnings from `density()`). If `FALSE`, warnings will be displayed as usual.

...

Additional arguments passed to `ggplot2` geoms.

Value

A `ggplot2` object showing the covariate distribution.

Examples

if (FALSE) { # \dontrun{
# Using an lbc_net object
plot_cov_bal(model, cov = "X1")

# Manual input
plot_cov_bal(Z = Z, Tr = Tr, wt = weights, cov = "X1")
} # }