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

Feature Request: Contrasting Simple Slopes #238

Open
jmgirard opened this issue Oct 11, 2023 · 1 comment
Open

Feature Request: Contrasting Simple Slopes #238

jmgirard opened this issue Oct 11, 2023 · 1 comment

Comments

@jmgirard
Copy link

jmgirard commented Oct 11, 2023

Let's say I fit a linear model with a continuous-by-categorical interaction.

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

I can use estimate_slopes() to see what the slope of the continuous variable is for each level of the categorical variable.

modelbased::estimate_slopes(fit, trend = "Petal.Length", at = "Species")
#> Estimated Marginal Effects
#> 
#> Species    | Coefficient |   SE |        95% CI | t(144) |      p
#> -----------------------------------------------------------------
#> setosa     |        0.39 | 0.26 | [-0.13, 0.90] |   1.49 | 0.138 
#> versicolor |        0.37 | 0.10 | [ 0.18, 0.56] |   3.89 | < .001
#> virginica  |        0.23 | 0.08 | [ 0.07, 0.40] |   2.86 | 0.005 
#> Marginal effects estimated for Petal.Length

But I don't think there is currently a way in {modelbased} to contrast those slopes. However, you can do so with emtrends().

emmeans::emtrends(fit, specs = pairwise ~ Species, var = "Petal.Length")
#> $emtrends
#>  Species    Petal.Length.trend     SE  df lower.CL upper.CL
#>  setosa                  0.388 0.2602 144  -0.1264    0.902
#>  versicolor              0.374 0.0961 144   0.1843    0.564
#>  virginica               0.234 0.0819 144   0.0725    0.396
#> 
#> Confidence level used: 0.95 
#> 
#> $contrasts
#>  contrast               estimate    SE  df t.ratio p.value
#>  setosa - versicolor      0.0136 0.277 144   0.049  0.9987
#>  setosa - virginica       0.1535 0.273 144   0.563  0.8400
#>  versicolor - virginica   0.1400 0.126 144   1.108  0.5105
#> 
#> P value adjustment: tukey method for comparing a family of 3 estimates

A {modelbased} wrapper for this functionality would be nice, especially if its arguments were more intuitive than emtrend's.

@strengejacke
Copy link
Member

In the long run, the goal is to use marginaleffects as backend (see #214), which will probably go along with adding more features.

For now, and if you're familiar with the syntax of ggeffects, you could also use the hypothesis_test() function. See a series of vignettes and examples starting here:
https://strengejacke.github.io/ggeffects/articles/introduction_comparisons_1.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants