# Rstanarm: extracting variance components

**URL:** <https://discourse.mc-stan.org/t/rstanarm-extracting-variance-components/4409>\
**Category:** rstanarm\
**Created:** [June 3, 2018, 4:21pm UTC](https://discourse.mc-stan.org/t/rstanarm-extracting-variance-components/4409 "2018-06-03T16:21:45Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [June 4, 2018, 2:55pm UTC](https://discourse.mc-stan.org/t/rstanarm-extracting-variance-components/4409/4 "2018-06-04T14:55:48Z")

</div>

Outside of a Gaussian, linear, no link function model, the idea of a decomposition of variance does not make sense. The general, correct, and Bayesian way to do things is

```
PPD <- posterior_predict(post)
vars <- apply(PPD, MARGIN = 1, FUN = var)

PPD_0 <- posterior_predict(post, re.form = ~ 0)
vars_0 <- apply(PPD_0, MARGIN = 1, FUN = var)

summary(vars - vars_0)

```

In general, it is better to just show a plot of the entire margin of the posterior distribution that is of interest, but if you are going to focus on a number it should usually be the mean or median. The posterior mode is not useful.

---

_[View the full topic](https://discourse.mc-stan.org/t/rstanarm-extracting-variance-components/4409)._
