dat <- iris
levels(dat$Species) <- c("Setosa", "Versicolor", "Virginica")
m <- lm(Sepal.Length ~ Species, data=iris)
modelbased::estimate_contrasts(m, contrast = "Species", backend = "emmeans")
#> Marginal Contrasts Analysis
#>
#> Level1 | Level2 | Difference | 95% CI | SE | t(147) | p
#> ------------------------------------------------------------------------------
#> setosa | versicolor | -0.93 | [-1.13, -0.73] | 0.10 | -9.03 | < .001
#> setosa | virginica | -1.58 | [-1.79, -1.38] | 0.10 | -15.37 | < .001
#> versicolor | virginica | -0.65 | [-0.86, -0.45] | 0.10 | -6.33 | < .001
#>
#> Variable predicted: Sepal.Length
#> Predictors contrasted: Species
#> p-values are uncorrected.
modelbased::estimate_contrasts(m, contrast = "Species", backend = "marginaleffects")
#> Marginal Contrasts Analysis
#>
#> Level1 | Level2 | Difference | SE | 95% CI | t(147) | p
#> ----------------------------------------------------------------------------
#> versicolor | setosa | 0.93 | 0.10 | [0.73, 1.13] | 9.03 | < .001
#> virginica | setosa | 1.58 | 0.10 | [1.38, 1.79] | 15.37 | < .001
#> virginica | versicolor | 0.65 | 0.10 | [0.45, 0.86] | 6.33 | < .001
#>
#> Variable predicted: Sepal.Length
#> Predictors contrasted: Species
#> p-values are uncorrected.
Created on 2026-07-11 with reprex v2.1.1
Level1 and Level2 are swapped.
Now, which one to change, my guess is that emmeans' treatment is currently more convenient: If you specify A as your reference factor, it makes sense to have the contrasts be expressed as "A minus X", so that positive differences means A > X?
@mattansb please correct me if I'm wrong
Created on 2026-07-11 with reprex v2.1.1
Level1 and Level2 are swapped.
Now, which one to change, my guess is that emmeans' treatment is currently more convenient: If you specify A as your reference factor, it makes sense to have the contrasts be expressed as "A minus X", so that positive differences means A > X?
@mattansb please correct me if I'm wrong