This function will apply sequentially:
Usage
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,
term_labels = NULL,
interaction_sep = " * ",
categorical_terms_pattern = "{level}",
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(),
keep_model = FALSE,
tidy_post_fun = NULL,
quiet = FALSE,
strict = FALSE,
...
)
Arguments
- model
(a model object, e.g.
glm
)
A model to be attached/tidied.- tidy_fun
(
function
)
Option to specify a custom tidier function.- conf.int
(
logical
)
Should confidence intervals be computed? (seebroom::tidy()
)- conf.level
(
numeric
)
Level of confidence for confidence intervals (default: 95%).- exponentiate
(
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 toFALSE
.- model_matrix_attr
(
logical
)
Whether model frame and model matrix should be added as attributes ofmodel
(respectively named"model_frame"
and"model_matrix"
) and passed through.- variable_labels
(
formula-list-selector
)
A named list or a named vector of custom variable labels.- term_labels
(
list
orvector
)
A named list or a named vector of custom term labels.- interaction_sep
(
string
)
Separator for interaction terms.- categorical_terms_pattern
(
glue pattern
)
A glue pattern for labels of categorical terms with treatment or sum contrasts (seemodel_list_terms_levels()
).- disambiguate_terms
(
logical
)
Should terms be disambiguated withtidy_disambiguate_terms()
? (defaultTRUE
)- disambiguate_sep
(
string
)
Separator fortidy_disambiguate_terms()
.- add_reference_rows
(
logical
)
Should reference rows be added?- no_reference_row
(
tidy-select
)
Variables for those no reference row should be added, whenadd_reference_rows = TRUE
.- add_pairwise_contrasts
(
logical
)
Applytidy_add_pairwise_contrasts()
?- pairwise_variables
(
tidy-select
)
Variables to add pairwise contrasts.- keep_model_terms
(
logical
)
Keep original model terms for variables where pairwise contrasts are added? (default isFALSE
)- pairwise_reverse
(
logical
)
Determines whether to use"pairwise"
(ifTRUE
) or"revpairwise"
(ifFALSE
), seeemmeans::contrast()
.- contrasts_adjust
(
string
)
Optional adjustment method when computing contrasts, seeemmeans::contrast()
(ifNULL
, useemmeans
default).- emmeans_args
(
list
)
List of additional parameter to pass toemmeans::emmeans()
when computing pairwise contrasts.- add_estimate_to_reference_rows
(
logical
)
Should an estimate value be added to reference rows?- add_header_rows
(
logical
)
Should header rows be added?- show_single_row
(
tidy-select
)
Variables that should be displayed on a single row, whenadd_header_rows
isTRUE
.- add_n
(
logical
)
Should the number of observations be added?- intercept
(
logical
)
Should the intercept(s) be included?- include
(
tidy-select
)
Variables to include. Default iseverything()
. See alsoall_continuous()
,all_categorical()
,all_dichotomous()
andall_interaction()
.- keep_model
(
logical
)
Should the model be kept as an attribute of the final result?- tidy_post_fun
(
function
)
Custom function applied to the results at the end oftidy_plus_plus()
(see note)- quiet
(
logical
)
Whetherbroom.helpers
should not return a message when requested output cannot be generated. Default isFALSE
.- strict
(
logical
)
Whetherbroom.helpers
should return an error when requested output cannot be generated. Default isFALSE
.- ...
other arguments passed to
tidy_fun()
Note
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.
See also
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_identify_variables()
,
tidy_remove_intercept()
,
tidy_select_variables()
Examples
if (FALSE) { # interactive()
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,
add_reference_rows = FALSE,
categorical_terms_pattern = "{level} / {reference_level}",
add_n = TRUE
)
ex2
if (.assert_package("gtsummary", boolean = TRUE)) {
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
}
}