Creating density plots for estimated latent distributions using conditional_effects() in cumulative models

Hi everyone,

I am analyzing data in which we want to see if an ordinal variable (i.e., the way in which children protest) depends on one of 4 experimental conditions

I am using a BRMS model

formula <- TypeofProtest ~ Condition

with a cumulative “cauchit” distribution

modelCCROrdinalLarge <- brm(formula, data = CCRDataStudy1, family = cumulative("cauchit"), prior = prior, iter = 100000, warmup = 40000, chains = 6, cores = 6, save_pars = save_pars(all = TRUE))

The model seems to work/fit well.
I then wanted to see if the conditions were any different. So first I used conditional_effects() to estimate the likelihood of different types of protest in the different conditionsby using

ConditionalEffects <- conditional_effects(modelCCROrdinalLarge, categorical = TRUE)

which (after some ggplot finetuning) looks like this:

However, as many in my field will find this type of analysis difficult to interpret, and like to also look at these ordinal variables in a more continuous way, I wanted to do that as well.
So I then did

ConditionalEffects <- conditional_effects(modelCCROrdinalLarge, categorical = FALSE)

However, this only yields HDI brackets

but not density plots. I am assuming these HDI’s are derived from an underlying distribution of the estimated latent continuous variable. Is there a way to plot that distribution so that it looks more like another graph I made (for protest probability), which looks like this:

But then for the brackets graph?

Thanks in advance!

Wouter Wolf

I’m not exactly sure what you’re trying to do because in the second plot the outcome is an average category value (if we recode the ordered categories as having values 1 through 4), while the third plot presents distributions of posterior probabilities. For now, in case it might be helpful, you might be able to get what you want by summarizing the posterior draws manually. For example:

library(tidybayes)
post = predicted_draws(modelCCROrdinalLarge, newdata=CCRDataStudy1, ndraws=100)

This will give you a data frame with 100 draws for each row of CCRDataStudy1, or, in general, total number of rows nrow(CCRDataStudy1) * ndraws.^1 Now you can summarize and plot the posterior as desired.

^1 You have 60,000 posterior draws for each row of your data (typically, only a few thousand draws are needed, so you might be able to reduce this), so the post data frame could be quite large, depending on the value you set for ndraws.

Hi Joels,

thanks for your reply!
Maybe I am misunderstanding what the second plot does, but I assumed that the HDI’s of the average category value from that plot stem from an estimated latent distribution of a continuous variable based on the original ordinal variable. So I thought that if there is an underlying distribution from which these HDI’s are taken, I wanted to plot the whole distribution rather than just the HDI’s. Or am I misunderstanding how conditional_effects() work and what they do precisely.

And thanks for the heads up about the sampling. Are you saying that 100.000 iterations over 6 chains is a bit more than necessary?

When I run your code and then plot it I get this graph, which seems slightly different from the latent continuous variable per condition (it seems like this is a distribution for the likelihood of each of the ordinal outcomes)?