easystats / easystats/modelbased

Is it possible to do standard contrasts across an interaction with the default-backend?

Open
#510 19 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement :boom: Feature idea :fire:
Dominant language
R
Stars
263
Forks
22
Avg merge
1h 22m
Merged PRs (30d)
11

Description

I'm trying to reproduce this analysis using modelbased::estimate_contrasts(). It's basically a set of 'out of the box' contrasts fitted across an interaction.

date_tib <- discovr::speed_date

date_afx <- afex::aov_4(date ~ strategy*looks*personality + (looks*personality|id), data = date_tib)
#> Contrasts set to contr.sum for the following variables: strategy

# Desired analysis using emmeans

three_way_emm <- emmeans::emmeans(date_afx, specs = c("strategy", "looks", "personality"), model = "multivariate")

emmeans::contrast(
  three_way_emm,
  interaction = c(strategy = "trt.vs.ctrl",
                  looks = "trt.vs.ctrl",
                  personality = "trt.vs.ctrl"),
  ref = 2,
  adjust = "holm"
  )
#>  strategy_trt.vs.ctrl looks_trt.vs.ctrl personality_trt.vs.ctrl estimate   SE
#>  Normal - Hard to get Low - Average     Low - Average               -4.7 4.07
#>  Normal - Hard to get High - Average    Low - Average              -36.2 4.65
#>  Normal - Hard to get Low - Average     High - Average              18.5 5.41
#>  Normal - Hard to get High - Average    High - Average              -5.8 6.02
#>  df t.ratio p.value
#>  18  -1.155  0.5263
#>  18  -7.789  <.0001
#>  18   3.421  0.0091
#>  18  -0.963  0.5263
#> 
#> P value adjustment: holm method for 4 tests

Created on 2025-06-11 with reprex v2.1.1

I can't see a way to set the contrasts across an interaction in estimate_contrasts() (without manually specifying weights but let's not go there ...). The function documentation doesn't mention an equivalent to interactiuon = that gets passed onto emmeans. But also, highly likley I just don't know how to use your function:) Is there a way? If not, is this something you'd impliment?

Incidentally, I'd prefer to do it without changing the backend to emmeans (because everything else in my book uses the default marginaleffects backend), but if it has to be changed then so be it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modelbased::estimate_contrasts() and its default marginaleffects backend, comparing them with the supplied emmeans::contrast() interaction example. Determine whether standard contrasts across all interaction terms are supported; done means the behavior is implemented or the supported limitation and usage are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.