Question for conditional_effects


I have a question about conditional_effects. When I have a brms object and put it inside the conditional_effects, which a low-level function was used to generate that data for its plot? I find I can extract the data inside the output list, but I find the row number of that data does not meet the data I used to fitted the brms model. So I was wondering how these data were generated.

I am doing a mixed-effect ordinal logit regression:
brm(formula = form ~ dose + (1|id), data = p504, family = cumulative(“probit”), prior = c(prior(normal(0,10), class = “Intercept”),
prior(cauchy(0,10), class = “b”), prior(cauchy(0,1), class = “sd”))

data p504 had 374 rows

I found with the code:
conditional_effects(brms_object, categorical = TRUE, probs = c(0.025, 0.975),robust = TRUE)
I got 300 rows with each probability of three outcomes column by column. It does not have id in the model.

However, when I try to use
fitted(brms_object, probs = c(0.025, 0.975, 0.25, 0.75)) which require id and dose.
I got 374 rows same to my data, with id show inside.

Can you explain how the data generated? is it different from the fitted function? If I want an output with 10 kinds of dose (my x, continue variable), without a specific id inside which the function of fitted required me to add id in the conditions (I guess it would be the population-level effect?), what should I do?

Thank you

Hi there,

There’s a lot to unpack in your post. The formula is helpful but without the data its use is limited. A small example with simulated data may be helpful.

Regardless, you should know that conditional_effects() has several knobs you can turn to fit your needs. As a default, ‘random effects’ are not included. In your case that means that the effect of ‘id’ is ignored. You can set re_formula=“NULL” in the conditional_effects() call to include these. Similarly, you can choose to use fitted() or predict() behind the scenes.

My understanding, which may be false, is that conditional_effects() won’t include all the rows in your data. Instead it sets up a data frame of ‘conditions’ (i.e. the value you are going to ‘condition’ the effect of an predictor on the outcome on). So, if you have a model like outcome ~ 1 + age, and you have 1000 different age values in the data set, conditional_effects() will basically create a sequence of 100 age values ranging from min(age) to max(age) and then use this as ‘new data’ into either fitted() or predict() and then plot the values. The 100 points is the default setting and gives smooth plots. Again, you can change this.

The documentation for the function explains this:

I’m not sure exactly what your goal was with the call to conditional_effects, if not to display the effect of dose on form. If my answer doesn’t help hopefully someone else weighs in!


Thank you, your answer helps me a lot. It makes sense that conditional_effects would produce the same results to fitted() by re_formula=“NULL”. However, I would also want to have the same results as conditonal_effects() from fitted(). Do you know how to turn off “random effects” in fitted()?

In the fitted() function the default is to include ‘random’ effects - ie re_formula is set to NULL. If you include re_formula=NA that will ignore all ‘random’ effects.

See the documentation for details:

Thank you so much