Hi all,
When plotting/extracting conditional effects (e.g., using posterior_epred / conditional_effects) credible intervals for a given effect will include all uncertainty including, for example, the between-subject differences in intercepts. Sometimes such credible intervals are not very informative because the between-subject variance in intercepts is irrelevant for conveying the slope effect that we are interested in.
I am wondering whether it is ok to remove the between-subject variability (with appropriately noting that in figure captions) in these situations? Is there a reason not to do this that I’m overlooking?
Is there a way of doing that within posterior_epred or conditional_effects? I’m sorry if this has an obvious solution, but I haven’t been able to find it looking into the documentation. Otherwise, I guess that the solution is to just manually plot the slopes and the associated group-level credible interval, or to average over the subjects.
Here’s example code in which I compare the credible intervals from conditional_effects and the ones obtained via fitted and then averaging over subjects:
library(lme4)
library(brms)
library(ggplot2)
library(gridExtra)
sleepstudy = sleepstudy
m = brm(
data = sleepstudy,
Reaction ~ Days + (Days | Subject),
family = gaussian,
iter = 2000,
chains = 4)
fit = fitted(m)
data = cbind(sleepstudy,fit)
colnames(data) = c("Reaction","Days","Subject","Reaction_pred")
# Plot
p1 = ggplot(data,aes(x=Days,y=Reaction_pred))+
geom_smooth(method="lm",se=.95) +
ylim(200,400)+
ggtitle('Average out the subject-level uncertainty')+
theme_clean()
p = conditional_effects(m,"Days",plot=FALSE)
p2 = plot(p,plot=FALSE)[[1]]+ ylim(200,400)+
ggtitle('Sample from the posterior')+
theme_clean()
grid.arrange(p1, p2, ncol=2)
Thank you very much for your help and sorry if this is a repeat question. I’ve seen a bunch of discussion on conditional_effects, but wasn’t able to find something that specifically addressed this issue.
Cheers,
Ivan