strengejacke / ggeffects

Estimated Marginal Means and Marginal Effects from Regression Models for ggplot2
https://strengejacke.github.io/ggeffects
Other
535 stars 34 forks source link

Bug in order of comparisons / labels when character vector is used in model #506

Closed strengejacke closed 2 months ago

strengejacke commented 2 months ago
library(ggeffects)

set.seed(1234)
dat <- data.frame(
  outcome = rbinom(n = 100, size = 1, prob = 0.35),
  var_binom = as.factor(rbinom(n = 100, size = 1, prob = 0.3)),
  var_cont = rnorm(n = 100, mean = 10, sd = 7),
  groups = sample(letters[1:2], size = 100, replace = TRUE)
)
m1 <- glm(outcome ~ var_binom * groups + var_cont, data = dat, family = binomial())
pr1 <- predict_response(m1, c("var_binom", "groups"))
out1 <- test_predictions(pr1, engine = "ggeffects")
out2 <- test_predictions(pr1)

out1
#> # Pairwise comparisons
#> 
#> var_binom | groups | Contrast |      95% CI |     p
#> ---------------------------------------------------
#> 0-0       |    b-a |    -0.04 | -0.25, 0.18 | 0.726
#> 0-1       |    a-a |     0.11 | -0.12, 0.34 | 0.358
#> 0-1       |    b-a |     0.07 | -0.16, 0.30 | 0.552
#> 0-1       |    b-b |     0.01 | -0.27, 0.30 | 0.940
#> 1-0       |    b-a |    -0.05 | -0.34, 0.24 | 0.735
#> 1-1       |    b-a |     0.06 | -0.24, 0.35 | 0.700
#> 
#> Contrasts are presented as probabilities.
out2
#> # Pairwise comparisons
#> 
#> var_binom | groups | Contrast |      95% CI |     p
#> ---------------------------------------------------
#> 0-1       |    b-b |     0.11 | -0.12, 0.34 | 0.356
#> 0-0       |    b-a |     0.04 | -0.18, 0.25 | 0.725
#> 0-1       |    b-a |     0.05 | -0.24, 0.34 | 0.736
#> 1-0       |    b-a |    -0.07 | -0.29, 0.16 | 0.546
#> 1-1       |    b-a |    -0.06 | -0.35, 0.24 | 0.700
#> 0-1       |    a-a |     0.01 | -0.28, 0.30 | 0.940
#> 
#> Contrasts are presented as probabilities.

Created on 2024-04-29 with reprex v2.1.0