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

How to recode emmeans::pairs() using marginaleffects #1289

Closed
perlatex opened this issue Dec 3, 2024 · 1 comment
Closed

How to recode emmeans::pairs() using marginaleffects #1289

perlatex opened this issue Dec 3, 2024 · 1 comment

Comments

@perlatex
Copy link

perlatex commented Dec 3, 2024

Sorry, because no one replied the post, I had to seek help here.

I am a big fan of the marginaleffects package and really appreciate its concise and easy-to-understand syntax. Whenever I encounter the emmeans function, I prefer to convert it into marginaleffects to study it. However, I recently came across this code, and I’m stuck—I can’t figure out how to proceed. The problem is as follows:

library(tidyverse)
library(lme4)
library(emmeans)
library(marginaleffects)

d <- mtcars %>% 
  as_tibble() %>% 
  select(cyl, vs, am, gear, carb) %>% 
  mutate(cyl = cyl > 6)

m <- lme4::glmer(
  cyl ~ vs * am + (1 | gear / carb),
  data     = d, 
  family   = binomial
)

m %>%
  emmeans::emmeans(specs = ~ vs + am, type = "response") %>%
  pairs(infer = T, adjust = "tukey") %>%
  as.data.frame()

ask

I can recode first line

m %>%
  emmeans::emmeans(specs = ~ vs + am, type = "response") %>%

as

library(marginaleffects)
m %>% 
  marginaleffects::predictions(
    newdata = datagrid(vs = unique, am = unique),
    type    = "response",
    re.form = NA
  ) %>% 
  as_tibble() 

but I can’t figure out the second line.

m %>%
  emmeans::emmeans(specs = ~ vs + am, type = "response") %>%
  pairs(infer = T, adjust = "tukey")   #<<

Could you please give me some help?
Thank you once again for your amazing package.

@vincentarelbundock
Copy link
Owner

Sorry, I am not an emmeans expert, and I don't know what this emmeans command does.

Since this website is for bug reports and feature requests, not general help, I will close the issue.

@vincentarelbundock vincentarelbundock closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2024
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