View source: R/tidy_add_estimate_to_reference_rows.R
tidy_add_estimate_to_reference_rows | R Documentation |
For categorical variables with a treatment contrast
(stats::contr.treatment()
) or a SAS contrast (stats::contr.SAS()
),
will add an estimate equal to 0
(or 1
if exponentiate = TRUE
)
to the reference row.
tidy_add_estimate_to_reference_rows(
x,
exponentiate = attr(x, "exponentiate"),
conf.level = attr(x, "conf.level"),
model = tidy_get_model(x),
quiet = FALSE
)
x |
( |
exponentiate |
( |
conf.level |
( |
model |
(a model object, e.g. |
quiet |
( |
For categorical variables with a sum contrast (stats::contr.sum()
),
the estimate value of the reference row will be equal to the sum of
all other coefficients multiplied by -1
(eventually exponentiated if
exponentiate = TRUE
), and obtained with emmeans::emmeans()
.
The emmeans
package should therefore be installed.
For sum contrasts, the model coefficient corresponds
to the difference of each level with the grand mean.
For sum contrasts, confidence intervals and p-values will also
be computed and added to the reference rows.
For other variables, no change will be made.
If the reference_row
column is not yet available in x
,
tidy_add_reference_rows()
will be automatically applied.
Other tidy_helpers:
tidy_add_coefficients_type()
,
tidy_add_contrasts()
,
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_plus_plus()
,
tidy_remove_intercept()
,
tidy_select_variables()
if (.assert_package("gtsummary", boolean = TRUE) && .assert_package("emmeans", boolean = TRUE)) {
df <- Titanic |>
dplyr::as_tibble() |>
dplyr::mutate(dplyr::across(where(is.character), factor))
glm(
Survived ~ Class + Age + Sex,
data = df, weights = df$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.SAS")
) |>
tidy_and_attach(exponentiate = TRUE) |>
tidy_add_reference_rows() |>
tidy_add_estimate_to_reference_rows()
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() |>
tidy_add_estimate_to_reference_rows()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.