-
Notifications
You must be signed in to change notification settings - Fork 59
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
Comparing levels of one predictor, ignoring other predictor #293
Comments
It depends on what you mean by "ignore". One interpretation of "ignore" is "the effect, conditional on the average of the ignored predictor" and another is "the effect, averaging out the ignored predictor". In linear models these tend to be the same, so the way you get there doesn't matter too much. In non-linear models these can be different, as taking the average on a linear scale and then putting it through a non-linear transformation is not the same as applying a non-linear transformation and then taking an average. There are a few approaches off the top of my head. Note that (again because linear model), they all give the same results on this model. (I'll be using Approach 1. Zero out the factor you don't care aboutSince you are using sum-to-zero coding with a linear model, one way to get the effect conditional on the average of the ignored predictor is to set the coefficients of the ignored predictor to 0. In brms you can do this by setting the factor to
So, we can change the call to stroop %>%
tidyr::expand(congruency, condition = NA) %>%
add_epred_draws(m1) %>%
compare_levels(.epred, by = congruency) %>%
median_qi()
Approach 2. Marginalize out the predictor you don't care aboutAnother alternative is to marginalize out (average over) the predictor you don't care about, which involves passing in the full prediction grid to stroop %>%
tidyr::expand(nesting(congruency, condition)) %>%
add_epred_draws(m1) %>%
group_by(.draw, congruency) %>%
summarise(.epred = mean(.epred), .groups = "drop") %>%
compare_levels(.epred, by = congruency) %>%
median_qi()
Note the result is exactly the same as before. Approach 3. Use
|
Wow, this was excellent. Thank you so much @mjskay for your super helpful and clear explanation. And also thanks for your amazing package. it is an absolute gem. |
My pleasure! |
Hi @mjskay
I was wondering if it is possible to use
compare_levels
withadd_fitted_draws
when we have a model with two predictors? I mean, can we compare levels of A and ignore B iny ~ A * B
? here is a simple reproducible example:The final code gives the "Each row of output must be identified by a unique combination of keys" error.
I am aware that we can do this using
emmeans
,contrasts
, andgather_emmeans_draws
but I prefer the former method as it is easier to transform values before comparing levels.Thank you.
The text was updated successfully, but these errors were encountered: