Learn R Programming

eVCGsampler (version 0.9.2)

plot_var: Visualize Covariate Distribution Across TG, VCG, and POOL

Description

Creates a plot to compare the distribution of a selected variable across three groups: TG (treated groups), VCG (virtual control group), and POOL (data pool).

Usage

plot_var(data, what = NULL, stratum = "in_stratum", group = "VCG", title = "")

Value

A ggplot2 object showing either:

  • A boxplot for continuous variables (more than 4 unique values).

  • A proportional bar chart for categorical variables (2–4 unique values).

Arguments

data

A balanced data frame (output of the VCG_sampler function)

what

A string specifying the name of the variable to be visualized.

stratum

A string specifying the name of the stratum variable (default is `"in_stratum"`)

group

A string specifying the column name used to define group membership (default is `"VCG"`).

title

Optional title for the plot.

Details

The function uses energy distance to quantify distributional differences between groups. For continuous variables, it overlays dashed lines for TG group statistics (mean, min, max) and displays sample sizes. For categorical variables, it uses color-coded bars and cumulative proportion lines to highlight imbalance.

Examples

Run this code

dat   <- data.frame(
  cov1  = rnorm(50, 10, 1),
  cov2  = rnorm(50, 7,  1),
  cov3  = rnorm(50, 5,  1),
  treated = rep(c(0, 1), c(35, 15))
)
  out <- VCG_sampler(treated ~ cov1 + cov2 + cov3, data=dat, n=5, plot=FALSE)
  plot_var(out, what='cov1', group='VCG')
  plot_var(out, what='cov2', group='VCG')

Run the code above in your browser using DataLab