[Experimental] Computes pairwise contrasts with emmeans::emmeans() and add them to the results tibble. Works only with models supported by emmeans, see vignette("models", package = "emmeans").

tidy_add_pairwise_contrasts(
  x,
  variables = all_categorical(),
  keep_model_terms = FALSE,
  pairwise_reverse = TRUE,
  contrasts_adjust = NULL,
  conf.level = attr(x, "conf.level"),
  emmeans_args = list(),
  model = tidy_get_model(x),
  quiet = FALSE
)

Arguments

x

a tidy tibble

variables

a vector indicating the name of variables for those pairwise contrasts should be added. Accepts tidyselect syntax. Default is all_categorical()

keep_model_terms

keep terms from the model?

pairwise_reverse

determines whether to use "pairwise" (if TRUE) or "revpairwise" (if FALSE), see emmeans::contrast()

contrasts_adjust

optional adjustment method when computing contrasts, see emmeans::contrast() (if NULL, use emmeans default)

conf.level

confidence level, by default use the value indicated previously in tidy_and_attach()

emmeans_args

list of additional parameter to pass to emmeans::emmeans() when computing pairwise contrasts

model

the corresponding model, if not attached to x

quiet

logical argument whether broom.helpers should not return a message when requested output cannot be generated. Default is FALSE

Note

If the contrasts column is not yet available in x, tidy_add_contrasts() will be automatically applied.

[Experimental] For multi-components models, such as zero-inflated Poisson or beta regression, support of pairwise contrasts is still experimental.

Examples

if (FALSE) { # interactive()
if (.assert_package("emmeans", boolean = TRUE)) {
  mod1 <- lm(Sepal.Length ~ Species, data = iris)
  mod1 %>%
    tidy_and_attach() %>%
    tidy_add_pairwise_contrasts()

  mod1 %>%
    tidy_and_attach() %>%
    tidy_add_pairwise_contrasts(pairwise_reverse = FALSE)

  mod1 %>%
    tidy_and_attach() %>%
    tidy_add_pairwise_contrasts(keep_model_terms = TRUE)

  mod1 %>%
    tidy_and_attach() %>%
    tidy_add_pairwise_contrasts(contrasts_adjust = "none")

  if (.assert_package("gtsummary", boolean = TRUE)) {
    mod2 <- glm(
      response ~ age + trt + grade,
      data = gtsummary::trial,
      family = binomial
    )
    mod2 %>%
      tidy_and_attach(exponentiate = TRUE) %>%
      tidy_add_pairwise_contrasts()
  }
}
}