 # Reordering brms marginal_effects plots by estimate values

Hi all,

For brms marginal_effects plots for categorical or ordinal data, is there an easy way to reorder the values by their brms_fit estimate values? I know this is possible in ggplot via aes(reorder), but am not too sure how this can be done in marginal_effects.

Thank you!

• Operating System: Windows 10 x64
• brms Version: 2.10.0

This seems like kind of a niche question because the size of parameter estimates is scale-dependent and not always directly comparable in terms of magnitude. For example, a coefficient estimate of `3` may be large when applied to `USDollars` but small when applied to a binary variable like `married`. And what if your intercept or scale parameter has a larger magnitude than your covariates?

So in any case I’m not sure the option you’re describing should be included in `brms` but you could hack the result you’re looking for by specifying the order of the parameter plots using the `effects` parameter like so:

``````N <- 100
a <- rnorm(N, 0, 1)
b <- rnorm(N, 0, 1)
c <- rnorm(N, 0, 1)

# effect sizes are: b > c > a
y <- rnorm(N,
1 * a +
3 * b +
2 * c, .1)

fit <- brm(y ~ a + b + c,
data = data.frame(a,b,c,y))

# extract magnitude of fixed effects, minus the intercept
no_intercept <- fixef(fit)[-1,"Estimate"]
# get names in order of the size of the parameter estimates
effect_names_in_order <- names(sort(no_intercept, decreasing=TRUE))

# plot marginal effects, specifying the effects in that order
marginal_effects(fit, effects = effect_names_in_order)
``````
1 Like

In the doc of marginal_effects you see examples of how to extract the underlying plot objects.

1 Like