-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
estimate_means(backend = "marginaleffects")
not calculating marginal means
#275
base: main
Are you sure you want to change the base?
Conversation
Should we add tests against emmeans, marginaleffects and ggeffects just so that we keep track of the similarities and discrepancies? |
Yes this is still work in progress. I'll add tests and also contacts with marginaleffects engine. |
One important thing is that we probably have to include a type dictionary: Else, we have other default types, leading to different results compared to emmeans or marginaleffects. See examples here: |
Ok, I added a lot of tests (still more to come, for now, all tests pass) and I think we now have the marginal means equivalent to emmeans with the marginaleffects-backend. And we even have "marginal predictions" for random effects, which is what we should have, IMHO. |
I think we could simplify |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
What is the purpose of dat <- mtcars
dat[c("gear", "vs", "am")] <- lapply(dat[c("gear", "vs", "am")], as.factor)
dat$am
#> [1] 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1
#> Levels: 0 1
model <- lm(mpg ~ gear * vs * am, data = dat)
modelbased::estimate_means(model, fixed = "am")
#> We selected `by = c("gear", "vs", "am")`.
#> Estimated Marginal Means
#>
#> am | gear | vs | Mean | SE | 95% CI
#> ----------------------------------------------
#> 0 | 3 | 0 | 15.05 | 1.04 | [12.90, 17.20]
#> 0 | 4 | 0 | | |
#> 0 | 5 | 0 | | |
#> 0 | 3 | 1 | 20.33 | 2.09 | [16.03, 24.63]
#> 0 | 4 | 1 | 21.05 | 1.81 | [17.33, 24.77]
#> 0 | 5 | 1 | | |
#>
#> Marginal means estimated at gear
modelbased::estimate_means(model, by = c("gear", "vs", "am = '0'"))
#> Estimated Marginal Means
#>
#> gear | vs | am | Mean | SE | 95% CI
#> ----------------------------------------------
#> 3 | 0 | 0 | 15.05 | 1.04 | [12.90, 17.20]
#> 4 | 0 | 0 | | |
#> 5 | 0 | 0 | | |
#> 3 | 1 | 0 | 20.33 | 2.09 | [16.03, 24.63]
#> 4 | 1 | 0 | 21.05 | 1.81 | [17.33, 24.77]
#> 5 | 1 | 0 | | |
#>
#> Marginal means estimated at gear Created on 2024-12-15 with reprex v2.1.1 |
fixed was just to "fix" variables at specific values, i.e. explicitly fix them without marginalizing over them |
Yes, but see my example, where you get the same result with |
ah yes fair then, yes I agree it makes sense to streamline the API here. For |
ok. what about changing |
ok, when these tests pass, I'd like to merge this PR and open a new one for contrasts, and then a new one for slopes. Tests are validated against our emmeans-engine, so we can - for |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #275 +/- ##
==========================================
+ Coverage 36.21% 37.22% +1.00%
==========================================
Files 25 27 +2
Lines 1226 1209 -17
==========================================
+ Hits 444 450 +6
+ Misses 782 759 -23 ☔ View full report in Codecov by Sentry. |
Fixes #273