# Prior\_covariance for stan\_glmer

**URL:** <https://discourse.mc-stan.org/t/prior-covariance-for-stan-glmer/23203>\
**Category:** Other\
**Created:** [June 26, 2021, 4:14pm UTC](https://discourse.mc-stan.org/t/prior-covariance-for-stan-glmer/23203 "2021-06-26T16:14:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlesm93](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/charlesm93/32/4634_2.png) [@charlesm93](https://discourse.mc-stan.org/u/charlesm93)\
**Post date:** [June 26, 2021, 4:14pm UTC](https://discourse.mc-stan.org/t/prior-covariance-for-stan-glmer/23203/1 "2021-06-26T16:14:32Z")

</div>

Hi all,  
I’m working through this excellent MRP case study, [GitHub - JuanLopezMartin/MRPCaseStudy](https://github.com/JuanLopezMartin/MRPCaseStudy), but I’d like to change the prior on the covariance matrix. This makes it easier to benchmark the code against a method @pgree has developed (i.e. I’d rather edit R than Fortran). Right now, this is the call:

```
  fit_sum <- stan_glmer(abortion_score ~ (1 | state) + (1 | ethnicity) + (1 | age) + 
                          (1 | educ) + male + repvote + factor(region),
                        data = df,
                        family = gaussian,
                        prior = normal(0, 1, autoscale = TRUE),
                        prior_covariance = decov(scale = 0.50),
                        adapt_delta = 0.99)

```

Hmmm… what is `decov`? Talking to the author of the case study, I was able to work out this formulation of the model:

```
y ~ normal(alpha_state
              + gamma_0 + gamma_south * South + gamma_northCentral * NorthCentral 
              + gamma_west * West + gamma_repVotes * RepVotes
              + alpha_age + alpha_ethnicity + alpha_education + beta * male + alpha_(male_ethnicity) 
              + alpha_(education_age) + alpha_(education_ethnicity), sigma_y)

alpha_state ~ normal(0, sigma_state * sd(y))
alpha_(*) ~ normal(0, sigma_alpha_(*) * sd(y))
beta ~ normal(0, beta * sd(y))
gamma_(*) ~ normal(0, sigma_gamma_(*) * sd(y))

sigma_(*) ~ exp(0.5)

```

My understanding is that the priors on all the sigmas (sigma\_state, sigma\_alpha, sigma\_y, etc.) end up being independent and an exp(0.5). What can I do to change this to a half-normal prior with diagonal covariance and scale sqrt(2)? I tried setting `prior_covariance = normal(0, sqrt(2)` but this returns the following error

```
Chain 1: 
Chain 1: Initialization between (-2, 2) failed after 100 attempts. 
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug
Error in dimnamesGets(x, value) : 
  invalid dimnames given for “dgCMatrix” object

```

Given using `prior_covariance = exp(0.5)` doesn’t work either, I’m assuming I need to specify a multivariate prior, but reading through the documentation, I couldn’t quite work out how to achieve this.

Haven’t used `stan_glmer` much, any help is appreciated!

---

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [June 27, 2021, 4:16pm UTC](https://discourse.mc-stan.org/t/prior-covariance-for-stan-glmer/23203/2 "2021-06-27T16:16:43Z")

</div>

I don’t think That this is possible in ratanarm. You don’t have that flexibility.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [June 30, 2021, 6:15pm UTC](https://discourse.mc-stan.org/t/prior-covariance-for-stan-glmer/23203/3 "2021-06-30T18:15:49Z")

</div>

Yeah unfortunately like @wds15 said this isn’t possible in rstanarm. Because we’re precompiling all the models there’s a limited set of options for priors. But I think this is probably doable in brms.
