Marginal_effects-ordinal data

Hi All,

I was hoping to have a surface plot using the output from marginal_effects (brms). My response is ordinal and fitted using cumulative family. My plan is to present the predicted probability for each response category as a surface plot. However, when I set ordinal=T option, marginal_effects only have two elements and the covriate1:covaraite2 object is not available. Is there any way to get this?

m<-marginal_effects(fit,surface=T)-> return three data frames (covaraite1:, covaraite2: and covaraite1:covaraite2:)

m<-marginal_effects(fit,ordinal=T, surface=T)-> return only two data frames

Belay

  • Operating System:Linux
  • brms Version:2.3.1

Due to the nature of the ordinal = TRUE plot, we cannot show a second covariate in the same way as we do otherwise for surface plots since one of the two axes of the plot is already taken by the ordinal categories.

I recommend using the conditions argument to generate a facet plot with different values of the second covariate. See ?marginal_effects for examples.

I am not successful using “conditions” for now. I see the difficulty, but it would have been great to see how P(Y=k) for a specific response category k change as a function of two covaraiates in a model fitted using te(covariate1,covaraite 2) and then we can compare this with the result for P(Y=k’) for a different response category k’ presented in a different surface plot.

Thank you for your help
Belay

So you are proposing showing each response category in a separate surface plot?

Exactly

You can achieve that yourself using the following recipe. Suppose we have to model

model = brm(y ~ t2(x1, x2), data = dat, family = cumulative())

Then extract fitted values from combinations of x1 and x2:

len = 100
x1_new <- seq(min(dat$x1), max(dat$x1), length.out = len)
x2_new <- seq(min(dat$x2), max(dat$x2), length.out = len)
newdata <- expand.grid(x1 = x1_new, x2 = x2_new)
fi = fitted(model, newdata = newdata)
str(fi)

This should result in a 3-D array of (summarized) predictions, which you can convert to a long data.frame containing the necessary variables. This data.frame can then be used to create the desired plot with ggplot2 using geom_raster and facet_wrap(<response category>)

1 Like

Thank you very much. This is exactly perfectly what I was looking for…!