Builds a side-by-side regression table from one or more fitted
bml models: one row per term, one column per model, with cells
formatted as estimate (conf.low, conf.high). Goodness-of-fit rows
(e.g. N and DIC) are appended at the bottom. The result is a
data.frame of character cells, ready to pass to
knitr::kable(), gt::gt(), etc.
For the underlying numeric values (e.g. to build custom tables or plots) use
the broom methods tidy.bml and glance.bml
directly; they also make modelsummary::modelsummary(list(m1, m2)) work
on bml models.
Usage
bmlCompare(
...,
component = "all",
terms = NULL,
labels = NULL,
stats = c("N", "DIC"),
digits = 3,
conf.level = 0.95
)Arguments
- ...
Fitted
bmlmodel objects, optionally named (e.g.,bmlCompare(base = m1, weighted = m2)). The names become the column headers. Unnamed models are labeled with the expressions they were passed as (e.g.,"m1").- component
Which parameters to include; passed to
tidy.bml. One of"all"(default),"fixed","random", or"weights".- terms
Optional character vector of term names selecting which rows to show and in what order (matched against the
termlabels fromtidy.bml, e.g."smoking_alter (mm.1)"). Terms not found are skipped with a warning. DefaultNULL: all terms incomponent, in their natural order.- labels
Optional character vector renaming the rows for display. Must be the same length as the selected
terms(so supplytermswhen usinglabels). DefaultNULL: keep the original term labels.- stats
Goodness-of-fit rows to append, in order. Any of
"N"(main-level units),"n.members"(member-level units), and"DIC". Default:c("N", "DIC"). Usecharacter(0)for none.- digits
Number of decimal places for the estimate and interval bounds. Default: 3.
- conf.level
Width of the equal-tailed credible interval. Default: 0.95. Other levels require the models to be fitted with
monitor = TRUE(seetidy.bml).
Value
A data.frame whose first column Term holds the term
labels (and the requested stats labels), followed by one character
column per model containing estimate (conf.low, conf.high) cells.
Author
Benjamin Rosche benrosche@nyu.edu
Examples
if (FALSE) { # \dontrun{
data(coalgov)
m1 <- bml(
Surv(dur_wkb, event_wkb) ~ 1 + majority +
mm(id = id(pid, gid), vars = vars(cohesion), w = w(~ 1/n), fn = fn("sum"), RE = TRUE),
family = weibull(),
data = coalgov
)
m2 <- bml(
Surv(dur_wkb, event_wkb) ~ 1 + majority +
mm(id = id(pid, gid), vars = vars(cohesion), w = w(~ pseat), fn = fn("sum"), RE = TRUE),
family = weibull(),
data = coalgov
)
bmlCompare("Equal" = m1, "Seat share" = m2)
# Select and relabel specific rows
bmlCompare(
"Equal" = m1, "Seat share" = m2,
terms = c("majority", "cohesion (mm.1)"),
labels = c("Majority", "Cohesion")
) |> knitr::kable()
} # }