Skip to contents

Transforms an oda_balance_table result (and optionally an smd_balance_table result) into a renderer-independent data structure suitable for Graphics v3 plotting.

Usage

oda_balance_plot_data(
  balance_table,
  smd_table = NULL,
  p_col = c("p_mc", "p_sidak", "p_bonferroni"),
  rank_by = c("abs_ess", "p", "abs_smd")
)

Arguments

balance_table

An "oda_balance_table" object from oda_balance_table.

smd_table

Optional "smd_balance_table" from smd_balance_table. When supplied, SMD columns are joined by attribute name and included in rows.

p_col

Character; which p-value column to use for the p_plot and significant columns in the output rows. One of "p_mc" (default), "p_sidak", "p_bonferroni".

rank_by

Character; how to rank covariates for display order. "abs_ess" (default): descending ESS/WESS (most imbalanced first). "p": ascending p (most significant first). "abs_smd": descending absolute SMD (requires smd_table).

Value

A list of class "oda_balance_plot_data" with elements:

rows

Data frame; one row per covariate, sorted by rank_by. Columns: attribute, attr_type, ess_display, ess_display_bar (clipped to [0, 100]), p_plot (selected p column), significant, significance_label ("*" or ""), rule_summary, abs_smd, wsmd_available, abs_smd_display (weighted if active), fit_ok, rank.

has_weights

Logical.

ess_label

Character; "WESS" or "ESS".

p_col_used

Character; selected p column name.

alpha

Numeric; significance threshold from metadata.

n_covariates

Integer.

n_significant

Integer; covariates significant on p_col_used.

rank_by

Character.

Details

This function does not fit any ODA models and does not accept group or X arguments. It is a pure transformation of pre-computed balance tables.

Examples

set.seed(1)
group <- c(rep(0L, 30), rep(1L, 30))
X     <- data.frame(age   = c(rnorm(30, 45, 8), rnorm(30, 55, 8)),
                    score = rnorm(60, 50, 10))
bt  <- oda_balance_table(group, X, mcarlo = TRUE, mc_iter = 500L)
smd <- smd_balance_table(group, X)
pd  <- oda_balance_plot_data(bt, smd_table = smd)
pd$rows[, c("attribute", "ess_display", "p_plot", "significant", "abs_smd")]
#>   attribute ess_display p_plot significant     abs_smd
#> 1       age    63.33333  0.000        TRUE 1.508260550
#> 2     score    20.00000  0.606       FALSE 0.003312628