add_glance {gtsummary} | R Documentation |
Add model statistics
Description
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()
).
Usage
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 = broom::glance
)
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 = broom::glance,
text_interpret = c("md", "html"),
sep1 = " = ",
sep2 = "; "
)
Arguments
x |
( |
include |
( |
label |
( |
fmt_fun |
( |
glance_fun |
function that returns model statistics. Default is
|
text_interpret |
String indicates whether source note text
will be interpreted with
|
sep1 |
Separator between statistic name and statistic.
Default is |
sep2 |
Separator between statistics. Default is |
Value
gtsummary table
Tips
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"))
Examples
mod <- lm(age ~ marker + grade, trial) |> tbl_regression()
# Example 1 ----------------------------------
mod |>
add_glance_table(
label = list(sigma = "\U03C3"),
include = c(r.squared, AIC, sigma)
)
# Example 2 ----------------------------------
mod |>
add_glance_source_note(
label = list(sigma = "\U03C3"),
include = c(r.squared, AIC, sigma)
)