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

tidy_add_header_rows

Add header rows variables with several terms


Description

For variables with several terms (usually categorical variables but could also be the case of continuous variables with polynomial terms or splines), tidy_add_header_rows() will add an additional row per variable, where label will be equal to var_label. These additional rows could be identified with header_row column.

Usage

tidy_add_header_rows(
  x,
  show_single_row = NULL,
  model = tidy_get_model(x),
  quiet = FALSE,
  strict = FALSE
)

Arguments

x

a tidy tibble

show_single_row

a vector indicating the names of binary variables that should be displayed on a single row. Accepts tidyselect syntax. Default is NULL. See also all_dichotomous()

model

the corresponding model, if not attached to x

quiet

logical argument whether broom.helpers should not return a message when requested output cannot be generated. Default is FALSE

strict

logical argument whether broom.helpers should return an error when requested output cannot be generated. Default is FALSE

Details

The show_single_row argument allows to specify a list of dichotomous variables that should be displayed on a single row instead of two rows.

The added header_row column will be equal to:

  • TRUE for an header row;

  • FALSE for a normal row of a variable with an header row;

  • NA for variables without an header row.

If the label column is not yet available in x, tidy_add_term_labels() will be automatically applied.

See Also

Examples

df <- Titanic %>%
  dplyr::as_tibble() %>%
  dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))

res <- df %>%
  glm(
    Survived ~ Class + Age + Sex,
    data = ., weights = .$n, family = binomial,
    contrasts = list(Age = contr.sum, Class = "contr.SAS")
  ) %>%
  tidy_and_attach() %>%
  tidy_add_variable_labels(labels = list(Class = "Custom label for Class")) %>%
  tidy_add_reference_rows()
res %>% tidy_add_header_rows()
res %>% tidy_add_header_rows(show_single_row = all_dichotomous())

if (requireNamespace("gtsummary")) {
  glm(
    response ~ stage + grade * trt,
    gtsummary::trial,
    family = binomial,
    contrasts = list(
      stage = contr.treatment(4, base = 3),
      grade = contr.treatment(3, base = 2),
      trt = contr.treatment(2, base = 2)
    )
  ) %>%
    tidy_and_attach() %>%
    tidy_add_reference_rows() %>%
    tidy_add_header_rows()
}

broom.helpers

Helpers for Model Coefficients Tibbles

v1.3.0
GPL-3
Authors
Joseph Larmarange [aut, cre] (<https://orcid.org/0000-0001-7097-700X>), Daniel D. Sjoberg [aut] (<https://orcid.org/0000-0003-0862-2018>)
Initial release

We don't support your browser anymore

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