Here is my model fit through brms:
fm <- brm(Value | se(SE) ~ time:class + (time|subj) + (1|subj:class), data=dd)
I’d like to plot the slope effect of ‘time’ with the 90% quantile band for each level of factor ‘class’ in a panel layout. Below is my starting code:
data_grid(time = seq_range(time n = 101)) %>%
ggplot(aes(x = time, y = Value, color = ordered(class), fill = ordered(class))) +
stat_lineribbon(aes(y = .prediction), .width = c(.95, .5, .05), alpha = 1/4) +
geom_point(data = dd)
It failed with the following error:
Error in get(sgroup, data) : object 'subj' not found
How to fix this?
Could you please provide a reproducible example to make it easier to answer your question?
It looks like the variable
subj doesn’t exist in your data (
dd I suppose).
Have you tried using
Thanks @matti for the suggestion!
plot(conditional_effects(fm, effects = "time:class"))
does show all the slopes within one panel. However, how can I separate those slope effects into a matrix of panels with something like facet_grid() in ggplot2? I hope this is simple so that I don’t have to create a reproducible example.
conditions argument as per documentation.
Thanks, Paul! Do you mean something like the following?
plot(marginal_effects(fm, effects = "time:class", conditions=make_conditions(fm, "class")))
It still plots everything in one panel.
Use a variable either in conditions or effects. Not both.
Thanks a lot, Paul, for providing so many nice and powerful tools!