Split conditional_effects plot in facets according to the value of the categorical DV

I use conditional_effects to plot my ordinal model, and would like to split the curves into different facets, but I can’t figure out how.

The plot I get is:

But here is a minimal reproducible example

library(tidyverse)
library(brms)
data <- data.frame(subject = rep(rep(c(1:10),5), 10),
                   judge   = sort(rep(c(1:5), 100)),
                   distance = runif(500),
                   response = round(runif(500,1,6)))


fit <- brm(data = data,
                   response ~ distance + (1|subject) + (1|judge),
                   family = cumulative("probit"),
                   chains = 1, 
                   save_all_pars = TRUE)

conditional_effects(fit, categorical = TRUE)

Adding facet_args does nothing, which makes sense because the docs say that this will work over different conditions, and what I would like to do is split the facets using different levels of the response, not of the predictors.

I also tried

plot(conditional_effects(fit, categorical = TRUE))[[1]] + ggplot2::facet_grid(~response) 

But that didn’t change anything in the plot.

I found useful pointers to split the response here https://bookdown.org/content/3686/ordinal-predicted-variable.html# (there are no subsections to link to directly). After fitting a model with no random effects (“fit23.9”), there are some helpful lines of data wrangling code that generate fitted lines for each level of the response and separates them in facets, but that does not look as good when I include my two random effects. I would be happy with the predictions as shown in conditional_effects, (not through the fitted lines) but split into facets.

I’m using brms 2.13.3 on MacOS Catalina

Thanks!

1 Like

Hi @Elisa and welcome to the Stan forums.

For categorical models like this, conditional_effects() returns a data frame with a cats__ variable that you can use:

ce <- conditional_effects(fit, categorical = TRUE)
str(ce[[1]])  # See what variables are available
plot(ce)[[1]] +
  facet_wrap("cats__")
5 Likes