broom.helpers (version 1.0.0)

tidy_plus_plus: Tidy a model and compute additional informations

Description

This function will apply sequentially:

Usage

tidy_plus_plus(
  model,
  tidy_fun = broom::tidy,
  conf.int = TRUE,
  exponentiate = FALSE,
  variable_labels = NULL,
  term_labels = NULL,
  add_reference_rows = TRUE,
  add_estimate_to_reference_rows = TRUE,
  add_header_rows = FALSE,
  show_single_row = NULL,
  intercept = FALSE,
  keep_model = FALSE,
  quiet = FALSE,
  strict = FALSE,
  ...
)

Arguments

model

a model to be attached/tidied

tidy_fun

option to specify a custom tidier function

conf.int

should confidence intervals be computed? (see broom::tidy())

exponentiate

logical indicating whether or not to exponentiate the coefficient estimates. This is typical for logistic and multinomial regressions, but a bad idea if there is no log or logit link. Defaults to FALSE.

variable_labels

a named list or a named vector of custom variable labels

term_labels

a named list or a named vector of custom term labels

add_reference_rows

should reference rows be added?

add_estimate_to_reference_rows

should an estimate value be added to reference rows?

add_header_rows

should header rows be added?

show_single_row

a vector indicating the names of binary variables that should be displayed on a single row, when add_header_rows is TRUE

intercept

should the intercept(s) be included?

keep_model

should the model be kept as an attribute of the final result?

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

...

other arguments passed to tidy_fun()

See Also

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

Examples

Run this code
# NOT RUN {
ex1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) %>%
  tidy_plus_plus()
ex1

df <- Titanic %>%
  dplyr::as_tibble() %>%
  dplyr::mutate(
    Survived = factor(Survived, c("No", "Yes"))
  ) %>%
  labelled::set_variable_labels(
    Class = "Passenger's class",
    Sex = "Gender"
  )

ex2 <- glm(
  Survived ~ Class + Age * Sex,
  data = df, weights = df$n,
  family = binomial
) %>%
  tidy_plus_plus(exponentiate = TRUE)
ex2

if (requireNamespace("gtsummary")) {
  ex3 <- glm(
    response ~ poly(age, 3) + stage + grade * trt,
    na.omit(gtsummary::trial),
    family = binomial,
    contrasts = list(
      stage = contr.treatment(4, base = 3),
      grade = contr.sum
    )
  ) %>%
    tidy_plus_plus(
      exponentiate = TRUE,
      variable_labels = c(age = "Age (in years)"),
      add_header_rows = TRUE,
      show_single_row = "trt",
      term_labels = c("poly(age, 3)3" = "Cubic age"),
      keep_model = TRUE
    )
  ex3
}
# }

Run the code above in your browser using DataLab