Add model statistics returned from broom::glance()
. Statistics can either
be appended to the table (add_glance_table()
), or added as a
table source note (add_glance_source_note()
).
add_glance_table(
x,
include = everything(),
label = NULL,
fmt_fun = list(everything() ~ label_style_sigfig(digits = 3), any_of("p.value") ~
label_style_pvalue(digits = 1), c(where(is.integer), starts_with("df")) ~
label_style_number()),
glance_fun = glance_fun_s3(x$inputs$x)
)
add_glance_source_note(
x,
include = everything(),
label = NULL,
fmt_fun = list(everything() ~ label_style_sigfig(digits = 3), any_of("p.value") ~
label_style_pvalue(digits = 1), c(where(is.integer), starts_with("df")) ~
label_style_number()),
glance_fun = glance_fun_s3(x$inputs$x),
text_interpret = c("md", "html"),
sep1 = " = ",
sep2 = "; "
)
(tbl_regression
)
a 'tbl_regression'
object
(tidy-select
)
names of statistics to include in output. Must be column
names of the tibble returned by broom::glance()
or from the glance_fun
argument. The include argument
can also be used to specify the order the statistics appear in the table.
(formula-list-selector
)
specifies statistic labels, e.g. list(r.squared = "R2", p.value = "P")
(formula-list-selector
)
Specifies the the functions used to format/round the glance statistics.
The default is to round
the number of observations and degrees of freedom to the nearest integer,
p-values are styled with style_pvalue()
and the remaining statistics
are styled with style_sigfig(x, digits = 3)
(function
)
function that returns model statistics. Default is
glance_fun()
(which is broom::glance()
for most model objects).
Custom functions must return a single row tibble.
(string
)
String indicates whether source note text
will be interpreted with
gt::md()
or gt::html()
. Must be "md"
(default) or "html"
.
(string
)
Separator between statistic name and statistic.
Default is " = "
, e.g. "R2 = 0.456"
(string
)
Separator between statistics. Default is "; "
gtsummary table
When combining add_glance_table()
with tbl_merge()
, the
ordering of the model terms and the glance statistics may become jumbled.
To re-order the rows with glance statistics on bottom, use the script below:
tbl_merge(list(tbl1, tbl2)) %>%
modify_table_body(~.x %>% arrange(row_type == "glance_statistic"))
mod <- lm(age ~ marker + grade, trial) |> tbl_regression()
# Example 1 ----------------------------------
mod |>
add_glance_table(
label = list(sigma = "\U03C3"),
include = c(r.squared, AIC, sigma)
)
Characteristic
Beta
95% CI1
p-value
1 CI = Confidence Interval
# Example 2 ----------------------------------
mod |>
add_glance_source_note(
label = list(sigma = "\U03C3"),
include = c(r.squared, AIC, sigma)
)
Characteristic
Beta
95% CI1
p-value
R² = 0.005; AIC = 1,473; σ = 14.6
1 CI = Confidence Interval