grouped_tbl_pivot_wider: Helpers for grouped tables generated with 'gtsummary'

View source: R/grouped_tbl_pivot_wider.R

grouped_tbl_pivot_widerR Documentation

Helpers for grouped tables generated with gtsummary

Description

A series of helpers for grouped tables generated by tbl_regression() in case of multinomial models, multi-components models or other grouped results. grouped_tbl_pivot_wider() allows to display results in a a wide format, with one set of columns per group. multinom_add_global_p_pivot_wider() is a specific case for multinomial models, when displaying global p-values in a wide format: it calls gtsummary::add_global_p(), followed by grouped_tbl_pivot_wider(), and then keep only the last column with p-values (see examples). Finally, as grouped regression tables doesn't have exactly the same structure as ungrouped tables, functions as gtsummary::bold_labels() do not always work properly. If the grouped table is kept in a long format, style_grouped_tbl() could be use to improve the output by styling variable labels, levels and/or group names. TO BE NOTED: to style group names, style_grouped_tbl() convert the table into a gt object with gtsummary::as_gt(). This function should therefore be used last. If the table is intended to be exported to another format, do not use style_grouped_tbl().

Usage

grouped_tbl_pivot_wider(x)

multinom_add_global_p_pivot_wider(
  x,
  ...,
  p_value_header = "**Likelihood-ratio test**"
)

style_grouped_tbl(
  x,
  bold_groups = TRUE,
  uppercase_groups = TRUE,
  bold_labels = FALSE,
  italicize_labels = TRUE,
  indent_labels = 4L,
  bold_levels = FALSE,
  italicize_levels = FALSE,
  indent_levels = 8L
)

Arguments

x

A grouped regression table generated with gtsummary::tbl_regression().

...

Additional arguments passed to gtsummary::add_global_p().

p_value_header

Header for the p-value column.

bold_groups

Bold group group names?

uppercase_groups

Convert group names to upper case?

bold_labels

Bold variable labels?

italicize_labels

Italicize variable labels?

indent_labels

Number of spaces to indent variable labels.

bold_levels

Bold levels?

italicize_levels

Italicize levels?

indent_levels

Number of spaces to indent levels.

Value

A gtsummary or a gt table.

Examples


mod <- nnet::multinom(
  grade ~ stage + marker + age,
  data = gtsummary::trial,
  trace = FALSE
)
tbl <- mod |> gtsummary::tbl_regression(exponentiate = TRUE)
tbl
tbl |> grouped_tbl_pivot_wider()


tbl |> multinom_add_global_p_pivot_wider() |> gtsummary::bold_labels()
tbl |> style_grouped_tbl()



guideR documentation built on June 8, 2025, noon