This function will apply sequentially:
tidy_plus_plus(
model,
tidy_fun = tidy_with_broom_or_parameters,
conf.int = TRUE,
conf.level = 0.95,
exponentiate = FALSE,
model_matrix_attr = TRUE,
variable_labels = NULL,
instrumental_suffix = " (instrumental)",
term_labels = NULL,
interaction_sep = " * ",
categorical_terms_pattern = "{level}",
relabel_poly = FALSE,
disambiguate_terms = TRUE,
disambiguate_sep = ".",
add_reference_rows = TRUE,
no_reference_row = NULL,
add_pairwise_contrasts = FALSE,
pairwise_variables = all_categorical(),
keep_model_terms = FALSE,
pairwise_reverse = TRUE,
contrasts_adjust = NULL,
emmeans_args = list(),
add_estimate_to_reference_rows = TRUE,
add_header_rows = FALSE,
show_single_row = NULL,
add_n = TRUE,
intercept = FALSE,
include = everything(),
group_by = auto_group_by(),
group_labels = NULL,
keep_model = FALSE,
tidy_post_fun = NULL,
quiet = FALSE,
strict = FALSE,
...
)(a model object, e.g. glm)
A model to be attached/tidied.
(function)
Option to specify a custom tidier function.
(logical)
Should confidence intervals be computed? (see broom::tidy())
(numeric)
Level of confidence for confidence intervals (default: 95%).
(logical)
Whether or not to exponentiate the coefficient estimates.
This is typical for logistic, Poisson and Cox models,
but a bad idea if there is no log or logit link; defaults to FALSE.
(logical)
Whether model frame and model matrix should be added as attributes of model
(respectively named "model_frame" and "model_matrix") and passed through.
(formula-list-selector)
A named list or a named vector of custom variable labels.
(string)
Suffix added to variable labels for instrumental variables (fixest models).
NULL to add nothing.
(list or vector)
A named list or a named vector of custom term labels.
(string)
Separator for interaction terms.
(glue pattern)
A glue pattern for labels of categorical terms with treatment
or sum contrasts (see model_list_terms_levels()).
Should terms generated with stats::poly() be relabeled?
(logical)
Should terms be disambiguated with
tidy_disambiguate_terms()? (default TRUE)
(string)
Separator for tidy_disambiguate_terms().
(logical)
Should reference rows be added?
(tidy-select)
Variables for those no reference row should be added,
when add_reference_rows = TRUE.
(logical)
Apply tidy_add_pairwise_contrasts()?
(tidy-select)
Variables to add pairwise contrasts.
(logical)
Keep original model terms for variables where
pairwise contrasts are added? (default is FALSE)
(logical)
Determines whether to use "pairwise" (if TRUE)
or "revpairwise" (if FALSE), see emmeans::contrast().
(string)
Optional adjustment method when computing contrasts,
see emmeans::contrast() (if NULL, use emmeans default).
(list)
List of additional parameter to pass to
emmeans::emmeans() when computing pairwise contrasts.
(logical)
Should an estimate value be added to reference rows?
(logical)
Should header rows be added?
(tidy-select)
Variables that should be displayed on a single row,
when add_header_rows is TRUE.
(logical)
Should the number of observations be added?
(logical)
Should the intercept(s) be included?
(tidy-select)
Variables to include. Default is everything().
See also all_continuous(), all_categorical(), all_dichotomous()
and all_interaction().
(tidy-select)
One or several variables to group by. Default is auto_group_by().
Use NULL to force ungrouping.
(string)
An optional named vector of custom term labels.
(logical)
Should the model be kept as an attribute of the final result?
(function)
Custom function applied to the results at the end of
tidy_plus_plus() (see note)
(logical)
Whether broom.helpers should not return a message when requested output
cannot be generated. Default is FALSE.
(logical)
Whether broom.helpers should return an error
when requested output cannot be generated. Default is FALSE.
other arguments passed to tidy_fun()
tidy_post_fun is applied to the result at the end of tidy_plus_plus()
and receive only one argument (the result of tidy_plus_plus()). However,
if needed, the model is still attached to the tibble as an attribute, even
if keep_model = FALSE. Therefore, it is possible to use tidy_get_model()
within tidy_fun if, for any reason, you need to access the source model.
Other tidy_helpers:
tidy_add_coefficients_type(),
tidy_add_contrasts(),
tidy_add_estimate_to_reference_rows(),
tidy_add_header_rows(),
tidy_add_n(),
tidy_add_pairwise_contrasts(),
tidy_add_reference_rows(),
tidy_add_term_labels(),
tidy_add_variable_labels(),
tidy_attach_model(),
tidy_disambiguate_terms(),
tidy_group_by(),
tidy_identify_variables(),
tidy_remove_intercept(),
tidy_select_variables()
# \donttest{
ex1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) |>
tidy_plus_plus()
ex1
#> # A tibble: 4 × 17
#> term variable var_label var_class var_type var_nlevels contrasts
#> <chr> <chr> <chr> <chr> <chr> <int> <chr>
#> 1 Sepal.Width Sepal.Wi… Sepal.Wi… numeric continu… NA NA
#> 2 Speciessetosa Species Species factor categor… 3 contr.tr…
#> 3 Speciesversicolor Species Species factor categor… 3 contr.tr…
#> 4 Speciesvirginica Species Species factor categor… 3 contr.tr…
#> # ℹ 10 more variables: contrasts_type <chr>, reference_row <lgl>, label <chr>,
#> # n_obs <dbl>, estimate <dbl>, std.error <dbl>, statistic <dbl>,
#> # p.value <dbl>, conf.low <dbl>, conf.high <dbl>
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,
add_reference_rows = FALSE,
categorical_terms_pattern = "{level} / {reference_level}",
add_n = TRUE
)
ex2
#> # A tibble: 6 × 17
#> term variable var_label var_class var_type var_nlevels contrasts
#> <chr> <chr> <chr> <chr> <chr> <int> <chr>
#> 1 Class2nd Class Passenger'… character categor… 4 contr.tr…
#> 2 Class3rd Class Passenger'… character categor… 4 contr.tr…
#> 3 ClassCrew Class Passenger'… character categor… 4 contr.tr…
#> 4 AgeChild Age Age character dichoto… 2 contr.tr…
#> 5 SexMale Sex Gender character dichoto… 2 contr.tr…
#> 6 AgeChild:SexMale Age:Sex Age * Gend… NA interac… NA NA
#> # ℹ 10 more variables: contrasts_type <chr>, label <chr>, n_obs <dbl>,
#> # n_event <dbl>, estimate <dbl>, std.error <dbl>, statistic <dbl>,
#> # p.value <dbl>, conf.low <dbl>, conf.high <dbl>
# }
# \donttest{
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 = all_dichotomous(),
term_labels = c("poly(age, 3)3" = "Cubic age"),
keep_model = TRUE
)
ex3
#> # A tibble: 17 × 19
#> term variable var_label var_class var_type var_nlevels header_row contrasts
#> <chr> <chr> <chr> <chr> <chr> <int> <lgl> <chr>
#> 1 NA age Age (in … nmatrix.3 continu… NA TRUE NA
#> 2 poly(… age Age (in … nmatrix.3 continu… NA FALSE NA
#> 3 poly(… age Age (in … nmatrix.3 continu… NA FALSE NA
#> 4 poly(… age Age (in … nmatrix.3 continu… NA FALSE NA
#> 5 NA stage T Stage factor categor… 4 TRUE contr.tr…
#> 6 stage1 stage T Stage factor categor… 4 FALSE contr.tr…
#> 7 stage2 stage T Stage factor categor… 4 FALSE contr.tr…
#> 8 stage3 stage T Stage factor categor… 4 FALSE contr.tr…
#> 9 stage4 stage T Stage factor categor… 4 FALSE contr.tr…
#> 10 NA grade Grade factor categor… 3 TRUE contr.sum
#> 11 grade1 grade Grade factor categor… 3 FALSE contr.sum
#> 12 grade2 grade Grade factor categor… 3 FALSE contr.sum
#> 13 grade3 grade Grade factor categor… 3 FALSE contr.sum
#> 14 trtDr… trt Chemothe… character dichoto… 2 NA contr.tr…
#> 15 NA grade:t… Grade * … NA interac… NA TRUE NA
#> 16 grade… grade:t… Grade * … NA interac… NA FALSE NA
#> 17 grade… grade:t… Grade * … NA interac… NA FALSE NA
#> # ℹ 11 more variables: contrasts_type <chr>, reference_row <lgl>, label <chr>,
#> # n_obs <dbl>, n_event <dbl>, estimate <dbl>, std.error <dbl>,
#> # statistic <dbl>, p.value <dbl>, conf.low <dbl>, conf.high <dbl>
# }