View source: R/tidy_add_reference_rows.R
| tidy_add_reference_rows | R Documentation |
For categorical variables with a treatment contrast
(stats::contr.treatment()), a SAS contrast (stats::contr.SAS())
a sum contrast (stats::contr.sum()), or successive differences contrast
(MASS::contr.sdif()) add a reference row.
tidy_add_reference_rows(
x,
no_reference_row = NULL,
model = tidy_get_model(x),
quiet = FALSE
)
x |
( |
no_reference_row |
( |
model |
(a model object, e.g. |
quiet |
( |
The added reference_row column will be equal to:
TRUE for a reference row;
FALSE for a normal row of a variable with a reference row;
NA for variables without a reference row.
If the contrasts column is not yet available in x,
tidy_add_contrasts() will be automatically applied.
tidy_add_reference_rows() will not populate the label
of the reference term. It is therefore better to apply
tidy_add_term_labels() after tidy_add_reference_rows()
rather than before. Similarly, it is better to apply
tidy_add_reference_rows() before tidy_add_n().
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_term_labels(),
tidy_add_variable_labels(),
tidy_attach_model(),
tidy_disambiguate_terms(),
tidy_group_by(),
tidy_identify_variables(),
tidy_plus_plus(),
tidy_remove_intercept(),
tidy_select_variables()
df <- Titanic |>
dplyr::as_tibble() |>
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
res <-
glm(
Survived ~ Class + Age + Sex,
data = df, weights = df$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.SAS")
) |>
tidy_and_attach()
res |> tidy_add_reference_rows()
res |> tidy_add_reference_rows(no_reference_row = all_dichotomous())
res |> tidy_add_reference_rows(no_reference_row = "Class")
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.