Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

add_glance

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 = NULL,
  glance_fun = broom::glance
)

add_glance_source_note(
  x,
  include = everything(),
  label = NULL,
  fmt_fun = NULL,
  glance_fun = broom::glance,
  text_interpret = c("md", "html"),
  sep1 = " = ",
  sep2 = "; "
)

Arguments

x

'tbl_regression' object

include

list of statistics to include in output. Must be column names of the tibble returned by broom::glance(). The include argument can also be used to specify the order the statistics appear in the table.

label

List of formulas specifying statistic labels, e.g. list(r.squared ~ "R2", p.value ~ "P")

fmt_fun

List of formulas where the LHS is a statistic and the RHS is a function to format/round the statistics. The default is style_sigfig(x, digits = 3)

glance_fun

function that returns model statistics. Default is broom::glance(). Custom functions must return a single row tibble.

text_interpret

String indicates whether source note text will be interpreted with gt::md() or gt::html(). Must be "md" (default) or "html".

sep1

Separator between statistic name and statistic. Default is " = ", e.g. "R2 = 0.456"

sep2

Separator between statistics. Default is "; "

Value

gtsummary table

Default Labels

The following statistics have set default labels when printed. When there is no default, the column name from broom::glance() is printed.

Statistic Name Default Label
r.squared
adj.r.squared Adjusted R²
p.value p-value
logLik Log-likelihood
statistic Statistic
df.residual Residual df
null.deviance Null deviance
df.null Null df
nevent N events
concordance c-index
std.error.concordance c-index SE
nobs No. Obs.
deviance Deviance
sigma Sigma

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"))

Example Output

Example 1

Example 2

Examples

mod <- lm(age ~ marker + grade, trial) %>% tbl_regression()

# Example 1 ----------------------------------
add_glance_ex1 <-
  mod %>%
  add_glance_table(
    label = list(sigma ~ "\U03C3"),
    include = c(r.squared, AIC, sigma)
  )

# Example 2 ----------------------------------
add_glance_ex2 <-
  mod %>%
  add_glance_source_note(
    label = list(sigma ~ "\U03C3"),
    include = c(r.squared, AIC, sigma)
  )

gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

v1.4.0
MIT + file LICENSE
Authors
Daniel D. Sjoberg [aut, cre] (<https://orcid.org/0000-0003-0862-2018>), Michael Curry [aut] (<https://orcid.org/0000-0002-0261-4044>), Margie Hannum [aut] (<https://orcid.org/0000-0002-2953-0449>), Joseph Larmarange [aut] (<https://orcid.org/0000-0001-7097-700X>), Karissa Whiting [aut] (<https://orcid.org/0000-0002-4683-1868>), Emily C. Zabor [aut] (<https://orcid.org/0000-0002-1402-4498>), Esther Drill [ctb] (<https://orcid.org/0000-0002-3315-4538>), Jessica Flynn [ctb] (<https://orcid.org/0000-0001-8310-6684>), Jessica Lavery [ctb] (<https://orcid.org/0000-0002-2746-5647>), Stephanie Lobaugh [ctb], Gustavo Zapata Wainberg [ctb] (<https://orcid.org/0000-0002-2524-3637>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.