Skip to content

estimate_slopes() with custom contrasts works with marginaleffects but not emmeans #618

@betahat

Description

@betahat

If I use the example from the documentation:

data(puppy_love, package = "modelbased")
cond_tx <- cbind("no treatment" = c(1, 0, 0), "treatment" = c(0, 0.5, 0.5))
model <- lm(happiness ~ puppy_love * dose, data = puppy_love)
estimate_slopes(model, "puppy_love", by = "dose", comparison = cond_tx)

things look fine, but if I specify the backend:

estimate_slopes(model, "puppy_love", by = "dose", comparison = cond_tx, backend = "emmeans")
estimate_slopes(model, "puppy_love", by = "dose", comparison = cond_tx, backend = "marginaleffects")

The emmeans gives output of:

Estimated Marginal Effects

dose       | Slope |   SE |        95% CI | t(24) |     p
---------------------------------------------------------
No puppies |  0.76 | 0.27 | [ 0.21, 1.31] |  2.86 | 0.009
15 mins    |  0.82 | 0.34 | [ 0.11, 1.53] |  2.40 | 0.025
30 mins    | -0.22 | 0.28 | [-0.79, 0.35] | -0.79 | 0.436

where the marginaleffects one gives output for the custom contrasts:

Estimated Marginal Effects

Parameter    | Slope |   SE |        95% CI | t(24) |     p
-----------------------------------------------------------
no treatment |  0.76 | 0.27 | [ 0.21, 1.31] |  2.86 | 0.009
treatment    |  0.30 | 0.22 | [-0.15, 0.75] |  1.37 | 0.184

Marginal effects estimated for puppy_love

Metadata

Metadata

Assignees

No one assigned

    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