Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrasting slopes: differences between backends #333

Closed
DominiqueMakowski opened this issue Jan 13, 2025 · 4 comments · Fixed by #332 or #393
Closed

Contrasting slopes: differences between backends #333

DominiqueMakowski opened this issue Jan 13, 2025 · 4 comments · Fixed by #332 or #393
Assignees
Labels
Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar

Comments

@DominiqueMakowski
Copy link
Member

emmeans acts up funny:

model <- lm(Petal.Width ~ Petal.Length * Species, data = iris)

modelbased::estimate_contrasts(model, contrast="Petal.Length", by="Species", backend="marginaleffectss")
#> Marginal Contrasts Analysis
#> 
#> Parameter              | Coefficient |   SE |        95% CI |     t |     p
#> ---------------------------------------------------------------------------
#> setosa - versicolor    |       -0.13 | 0.16 | [-0.43, 0.17] | -0.83 | 0.808
#> setosa - virginica     |        0.04 | 0.15 | [-0.26, 0.34] |  0.27 | 0.808
#> versicolor - virginica |        0.17 | 0.07 | [ 0.03, 0.31] |  2.41 | 0.048
#> 
#> Marginal contrasts estimated at Petal.Length
#> p-value adjustment method: Holm (1979)
modelbased::estimate_contrasts(model, contrast="Petal.Length", by="Species", backend="emmeans")
#> Marginal Contrasts Analysis
#> 
#> Level1                       |                       Level2 |    Species
#> ------------------------------------------------------------------------
#> Petal.Length1                | Petal.Length1.65555555555556 |     setosa
#> Petal.Length1                | Petal.Length1.65555555555556 | versicolor
#> Petal.Length1                | Petal.Length1.65555555555556 |  virginica
#> Petal.Length1                | Petal.Length2.31111111111111 |     setosa
#> Petal.Length1                | Petal.Length2.31111111111111 | versicolor
#> Petal.Length1                | Petal.Length2.31111111111111 |  virginica
#> Petal.Length1                | Petal.Length2.96666666666667 |     setosa
#> Petal.Length1                | Petal.Length2.96666666666667 | versicolor
#> Petal.Length1                | Petal.Length2.96666666666667 |  virginica
#> Petal.Length1                | Petal.Length3.62222222222222 |     setosa
#> Petal.Length1                | Petal.Length3.62222222222222 | versicolor
#> Petal.Length1                | Petal.Length3.62222222222222 |  virginica
#> ...
#> 
#> Marginal contrasts estimated at Petal.Length
#> p-value adjustment method: Holm (1979)

Created on 2025-01-13 with reprex v2.1.1

@DominiqueMakowski DominiqueMakowski linked a pull request Jan 13, 2025 that will close this issue
@strengejacke
Copy link
Member

You're a bit out of date with the modelbased version, the first example currently doesn't work. Fixed in #331

@strengejacke strengejacke added Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar labels Jan 14, 2025
@strengejacke
Copy link
Member

The question is, how much work do we want to put in maintaining the emmeans backend? I haven't looked much into the code for emmeans yet.

@DominiqueMakowski
Copy link
Member Author

Not sure long term, but short term it'd be good to be able to show that we can reproduce its result as - at least in my mind - emmeans is kind of the baseline / ground truth.

@strengejacke
Copy link
Member

Ok, and we want:

model <- lm(Petal.Width ~ Petal.Length * Species, data = iris)
emmeans::emtrends(model, "Species", "Petal.Length") |>
  emmeans::contrast(method = "pairwise")
#>  contrast               estimate     SE  df t.ratio p.value
#>  setosa - versicolor     -0.1298 0.1560 144  -0.835  0.6821
#>  setosa - virginica       0.0409 0.1530 144   0.268  0.9613
#>  versicolor - virginica   0.1708 0.0708 144   2.412  0.0449
#> 
#> P value adjustment: tukey method for comparing a family of 3 estimates

Created on 2025-02-13 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar
Projects
None yet
2 participants