# How to obtain odds-ratio for random effects from rstanarm results and visualize them?

Greetings all,

I’ve been trying to obtain odds ratio for random effects. I’ve used the parameters package to get summary of posterior distribution and ploted the results, however I get fixed effects on the plot. How can I get the results for random effects in model and more importantly how can I visualize them?

Here is my model and codes I’ve used.

``````results <- stan_glmer(Alternation ~  Agent_Pos + Agent_Animacy +  Semantic_Class + Theme_Pos + Theme_Animacy + Theme_length + Recipient_Pos + Recipient_Animacy + Recipient_length + (1 | Native_Language), data = df, family = binomial(link = 'logit'), init_r = 0.5, QR = TRUE)
model <- model_parameters(results, exponentiate = TRUE)
plot(model)
``````

Since Native_language (factor with 27 levels) was provided as the random effects in the model, I would like to visualize odds ratio for each level in the factor. I guess adding `effects = "random"` just assume all variable in the model as random.

Output from the `model_parameters(results, exponentiate = TRUE)`

## Parameter | Median | 95% CI | pd | % in ROPE | Rhat | ESS | Prior

(Intercept) | 0.30 | [0.14, 0.72] | 99.88% | 0% | 0.999 | 5968.00 | Normal (0 ± 2.50)
Agent_PosPRON | 0.88 | [0.72, 1.09] | 87.30% | 73.16% | 1.000 | 7166.00 | Normal (0 ± 2.50)
Agent_PosPROPN | 1.06 | [0.75, 1.51] | 62.15% | 68.98% | 1.000 | 7977.00 | Normal (0 ± 2.50)
Agent_AnimacyInanimate | 0.67 | [0.55, 0.83] | 99.98% | 0% | 1.000 | 7148.00 | Normal (0 ± 2.50)
Semantic_Classc | 0.42 | [0.27, 0.66] | 100% | 0% | 0.999 | 7574.00 | Normal (0 ± 2.50)
Semantic_Classf | 1.65 | [1.18, 2.28] | 99.98% | 0.63% | 1.000 | 7729.00 | Normal (0 ± 2.50)
Semantic_Classnd | 0.16 | [0.09, 0.30] | 100% | 0% | 1.000 | 6717.00 | Normal (0 ± 2.50)
Semantic_Classp | 0.06 | [0.03, 0.14] | 100% | 0% | 1.000 | 5814.00 | Normal (0 ± 2.50)
Semantic_Classt | 1.57 | [1.15, 2.12] | 99.75% | 2.92% | 1.000 | 8817.00 | Normal (0 ± 2.50)
Theme_PosPRON | 3.52 | [2.31, 5.25] | 100% | 0% | 0.999 | 6166.00 | Normal (0 ± 2.50)
Theme_PosPROPN | 1.57 | [0.54, 3.95] | 80.80% | 19.18% | 1.000 | 7146.00 | Normal (0 ± 2.50)
Theme_AnimacyInanimate | 1.81 | [1.08, 2.96] | 99.15% | 3.05% | 0.999 | 6099.00 | Normal (0 ± 2.50)
Theme_length | 0.32 | [0.20, 0.50] | 100% | 0% | 1.000 | 7644.00 | Normal (0 ± 2.50)
Recipient_PosPRON | 0.23 | [0.18, 0.29] | 100% | 0% | 1.000 | 8672.00 | Normal (0 ± 2.50)
Recipient_PosPROPN | 1.01 | [0.60, 1.76] | 52.48% | 53.01% | 0.999 | 7980.00 | Normal (0 ± 2.50)
Recipient_AnimacyInanimate | 1.86 | [1.48, 2.35] | 100% | 0% | 0.999 | 7963.00 | Normal (0 ± 2.50)
Recipient_length | 9.90 | [5.67, 16.95] | 100% | 0% | 1.000 | 6322.00 | Normal (0 ± 2.50)

Allright, I guess I missed the code `group_level = "TRUE"`. I’ve found the answer to my own question. So next question is how to visualize them as percentages and how can I add labels to chart?

1 Like

Glas you were able to resolve this. I admit I am not sure using the `parameters` package here gives you much advantage over extracting the parameters directly with `rstanarm::as.XXX` (which gives you all the variables by default).

There is no direct mapping between odds ratios and percentages - odds ratios are a relative measure and you need to have a baseline against which you interpret them to move to the absolute (percentage) scale. The same odds ratios will result in the different risk ratio/risk difference depending on which baseline you choose.

If you are interested in a comparison between specific groups, then I think the easiest way is to use `posterior_epred` to create samples of predictions for both groups and then subtract the samples to get samples of the absolute difference. This will automatically include all model terms as needed and account for any correlations you have in your posterior.

Does that make sense?

Best of luck with your model!

1 Like

Well it makes ‘partial’ sense to me :) I’m trying to report the results as less technical as possible while also I am trying to learn all about regression and bayes. Still not sure how to report or visualize results for random effects. Indeed not many paper provide results for random coeff. However, in my case it is the focus of the study.

I guess main problem is due to discrete indepedent variables and discrete response. So far, every example I’ve replicated is on continous variables.

I’ve found an awesome guide here I can now say that case is solved :)

1 Like