Skip to content

Feature Request: Contrasting Simple Slopes #238

@jmgirard

Description

@jmgirard

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions