broom.helpers (version 1.0.0)

tidy_add_term_labels: Add term labels

Description

Will add term labels in a label column, based on:

  1. labels provided in labels argument if provided;

  2. factor levels for categorical variables coded with treatment, SAS or sum contrasts;

  3. variable labels when there is only one term per variable;

  4. term name otherwise.

Usage

tidy_add_term_labels(
  x,
  labels = NULL,
  interaction_sep = " * ",
  model = tidy_get_model(x),
  quiet = FALSE,
  strict = FALSE
)

Arguments

x

a tidy tibble

labels

an optional named list or named vector of custom term labels

interaction_sep

separator for interaction terms

model

the corresponding model, if not attached to x

quiet

logical argument whether broom.helpers should return an error 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

If the variable_label column is not yet available in x, tidy_add_variable_labels() will be automatically applied. If the contrasts column is not yet available in x, tidy_add_contrasts() will be automatically applied.

It is possible to pass a custom label for any term in labels, including interaction terms.

See Also

Other tidy_helpers: tidy_add_contrasts(), tidy_add_estimate_to_reference_rows(), tidy_add_header_rows(), tidy_add_reference_rows(), tidy_add_variable_labels(), tidy_attach_model(), tidy_identify_variables(), tidy_plus_plus(), tidy_remove_intercept()

Examples

Run this code
# NOT RUN {
df <- Titanic %>%
  dplyr::as_tibble() %>%
  dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) %>%
  labelled::set_variable_labels(
    Class = "Passenger's class",
    Sex = "Sex"
  )

df %>%
  glm(Survived ~ Class * Age * Sex, data = ., weights = .$n, family = binomial) %>%
  tidy_and_attach() %>%
  tidy_add_term_labels()
# }

Run the code above in your browser using DataLab