# Interpreting and extracting residual variance for multiple groups

**URL:** <https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764>\
**Category:** brms\
**Tags:** interpret-results\
**Created:** [October 8, 2021, 1:13am UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764 "2021-10-08T01:13:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_A](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jack_a/32/9695_2.png) [@Jack\_A](https://discourse.mc-stan.org/u/Jack_A)\
**Post date:** [October 8, 2021, 1:13am UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/1 "2021-10-08T01:13:34Z")

</div>

Hi,

I am currently doing an analysis of population differences in behavioural variation across a temperature gradient. Here, individuals from 2 populations were repeatedly tested at both a Low temperature (3 repeated measures) and a high temperature (3 repeated measures).

A simplified example of my dataset is as follows:

```
ID Pop Temp_measured Temp_treatment Trial Behaviour
1 A 25.1 Low 1 603
1 A 28.2 High 2 927
1 A 24.8 Low 3 715
1 A 27.4 High 4 1068
1 A 25.0 Low 5 541
1 A 28.1 High 6 854
2 B 25.0 Low 1 733
2 B 28.1 High 2 813
etc.

```

One of the things I am interested in investigating is the residual variance of each Population (A or B) at each temperature treatment (Low or High). I have therefore fit something similar to the following model using the `brms` package:

```
Behaviour ~ Pop*scale(Temp_measured)+
                        scale(Trial)+
                       (scale(Temp_measured)|gr(ID, by = Pop)), 
                        sigma ~ 0 + Pop*Temp_treatment, family = gaussian)

```

From this model, I get the following output under Population-Level Effects:

```
                             Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma_PopA 5.51 0.07 5.49 5.73 1.00 8353 8811
sigma_PopB 6.22 0.11 6.07 6.51 1.00 6080 7977
sigma_Temp_treatmentLow 0.39 0.09 0.18 0.53 1.00 8325 9092
sigma_PopB:Temp_treatmentLow -0.72 0.13 -0.89 -0.43 1.00 8253 9088

```

My questions are:

1. Am I correct in that `sigma_PopA` and `sigma_PopB` represent the residual variation (on the log scale) for population A and B, respectively, at the High temperature treatment?

2. Also, is there a simple way to extract the residual variance for each population at the ‘Low’ temperature treatment? Is it a case of combining the posterior distributions?  
For example, something like…

```
Vresid_PopB_Low <- exp(posterior_samples(Model)$"b_sigma_PopB")^2 + exp(posterior_samples(Model)$"b_sigma_PopB:Temp_treatmentLow")^2 

```

Any help or guidance would be greatly appreciated!

Many thanks!

---

<div class="post-metadata">

**Author:** ![Solomon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/solomon/32/2495_2.png) [@Solomon](https://discourse.mc-stan.org/u/Solomon)\
**Post date:** [October 8, 2021, 1:42pm UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/2 "2021-10-08T13:42:03Z")

</div>

I believe you’re correct in your interpretation of 1.

As to 2, the old method would be to work directly with the posterior draws using the `posterior_samples()` function. That function still works, but was depreciated in the recent **brms** update. You’ll have to look through the reference manual for the current recommended practice. I’m not totally up on it, yet.

---

<div class="post-metadata">

**Author:** ![Jack\_A](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jack_a/32/9695_2.png) [@Jack\_A](https://discourse.mc-stan.org/u/Jack_A)\
**Post date:** [October 9, 2021, 6:22am UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/3 "2021-10-09T06:22:38Z")

</div>

Great, thanks for the help Solomon!

Would I be correct as well then that `sigma_Temp_treatmentLow` represents the difference in residual variation when Population A are tested in the Low temperature treatment? And vice versa for `sigma_PopB:Temp_treatmentLow` and Population B? Just want to make sure I am understanding the output correctly.

Provided this is correct, does combining the `sigma_PopA` and `sigma_Temp_treatmentLow` posterior distributions (using the current recommended practice outlined in the reference manual) in order to get a posterior distribution for PopA at the Low temperature treatment sound like a sensible idea?

Thanks again for the help. I really appreciate it.

---

<div class="post-metadata">

**Author:** ![Solomon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/solomon/32/2495_2.png) [@Solomon](https://discourse.mc-stan.org/u/Solomon)\
**Post date:** [October 10, 2021, 8:48pm UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/4 "2021-10-10T20:48:50Z")

</div>

It’s going to be hard for me to keep up with the exact interpretation of your model, given its complexity and so on. Instead, here are a couple strategies for thinking about and working with models which include a linear model on \sigma:

- Broadly speaking, interpret the coefficients in the model for \sigma much the same as you would interpret the coefficients for \mu. The only big difference is you’re typically modeling \log \sigma, so convert as necessary.
- Any time you’re working with a new model (or even with new data), start with very simple models and slowly build up to more complex ones. Also, never jump up to a complex model until you have 100 \% nailed down all the parameters in the simpler one. In your case, consider simplifying your model for \log \sigma and build up once you’re confident you understand the parameters. I use this kind workflow _all_ the time.

---

<div class="post-metadata">

**Author:** ![Jack\_A](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jack_a/32/9695_2.png) [@Jack\_A](https://discourse.mc-stan.org/u/Jack_A)\
**Post date:** [October 11, 2021, 9:40pm UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/5 "2021-10-11T21:40:07Z")

</div>

Great, thanks for the help Solomon.

---

<div class="post-metadata">

**Author:** ![bachlaw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bachlaw/32/5691_2.png) [@bachlaw](https://discourse.mc-stan.org/u/bachlaw)\
**Post date:** [November 8, 2023, 12:12am UTC](https://discourse.mc-stan.org/t/interpreting-and-extracting-residual-variance-for-multiple-groups/24764/6 "2023-11-08T00:12:39Z")

</div>

great reminder to be mindful of the log scale for sigma, particularly when you have different coefficients on different scales in the same table.
