df <- data.frame(
x = rnorm(1000),
y = rep_len(c("A - High", "A - Low", "B - High", "B - Low"), 1000)
)
model <- lm(x ~ y, data=df)
modelbased::estimate_contrasts(model, contrast = "y", backend = "marginaleffects") # Works
#> Marginal Contrasts Analysis
#>
#> Level1 | Level2 | Difference | SE | 95% CI | t(996) | p
#> ------------------------------------------------------------------------
#> A - Low | A - High | 0.02 | 0.09 | [-0.16, 0.19] | 0.17 | 0.863
#> B - High | A - High | 0.01 | 0.09 | [-0.16, 0.18] | 0.13 | 0.898
#> B - Low | A - High | -0.05 | 0.09 | [-0.22, 0.13] | -0.53 | 0.597
#> B - High | A - Low | -3.95e-03 | 0.09 | [-0.18, 0.17] | -0.05 | 0.964
#> B - Low | A - Low | -0.06 | 0.09 | [-0.23, 0.11] | -0.70 | 0.483
#> B - Low | B - High | -0.06 | 0.09 | [-0.23, 0.11] | -0.66 | 0.511
#>
#> Variable predicted: x
#> Predictors contrasted: y
#> p-values are uncorrected.
modelbased::estimate_contrasts(model, contrast = "y", backend = "emmeans")
#> Marginal Contrasts Analysis
#>
#> Level | X2 | X3 | X4 | Difference | 95% CI | SE | t(996) | p
#> -------------------------------------------------------------------------------
#> (A | Low) | (A | High) | 0.02 | [-0.16, 0.19] | 0.09 | 0.17 | 0.863
#> (B | High) | (A | High) | 0.01 | [-0.16, 0.18] | 0.09 | 0.13 | 0.898
#> (B | High) | (A | Low) | -3.95e-03 | [-0.18, 0.17] | 0.09 | -0.05 | 0.964
#> (B | Low) | (A | High) | -0.05 | [-0.22, 0.13] | 0.09 | -0.53 | 0.597
#> (B | Low) | (A | Low) | -0.06 | [-0.23, 0.11] | 0.09 | -0.70 | 0.483
#> (B | Low) | (B | High) | -0.06 | [-0.23, 0.11] | 0.09 | -0.66 | 0.511
#>
#> Variable predicted: x
#> Predictors contrasted: y
#> p-values are uncorrected.
Created on 2026-07-28 with reprex v2.1.1
Created on 2026-07-28 with reprex v2.1.1