Prior_covariance for stan_glmer

Hi all,
I’m working through this excellent MRP case study, GitHub - 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!

1 Like

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

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.