stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
389 stars 133 forks source link

Specifying several independent priors #449

Closed alexandrahotti closed 4 years ago

alexandrahotti commented 4 years ago

Summary

I want to know how to specify several independent priors in the stan_glm() function.

Description:

I am using the function stan_glm() in R. I am using 4 predictor variables and I want to specify a univariate independent prior for each regression parameter. Right now I am trying to include each prior by placing them in a list through the following code snippet:

  poisson.model.stan <- stan_glm(Count ~ v1 + v2 + v3 + v4, 
                                 family = poisson(link=log),
                                  data=data,
                                 chains = 4, cores = 5, seed = 55, iter = 100000,
                                 offset=log(exposure), prior_intercept = normal(-2,1), 
                                 prior = c(normal(-0.2, 0.05),
                                           normal(0.1, 0.05),
                                           normal(0.3, 0.05),
                                           normal(0.04, 0.05)))

However, I am not sure whether this is the correct way of specifying my priors. To summarize, how do I specify several independent priors in the stan_glm() function?

RStanARM Version:

‘2.19.2’

R Version:

‘3.6.2’

Operating System:

Windows 10

jgabry commented 4 years ago

Hi @alexandrahotti thanks for your question. instead of concatenating several calls to normal() together, you just use one call to normal() and concatenate the arguments together. In this case that would be:

# you can also make the scale argument a vector if you have different scales
prior = normal(location = c(-0.2, 0.1, 0.3, 0.04), scale = 0.05)

A few clarifications though:

prior = normal(location = c(-0.2, 0.1, 0.3, 0.04), scale = 0.05, autoscale = FALSE)

to avoid rstanarm rescaling your priors for you (if you're sure you want a prior scale of 0.05). In the newest version of rstanarm (just released but CRAN binaries might still be building) it won't be necessary to specify autoscale=FALSE.

While I'm at it, a few other comments on your stan_glm() specification that I hope are helpful:

alexandrahotti commented 4 years ago

Thank you very much! This, solved my issue. Also, thank you for the suggestions about the iterations.

jgabry commented 4 years ago

Great, glad that helped!