Closed alexandrahotti closed 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:
That's assuming your predictors are numeric and not factor variables. Is that right? If they're factors then they will get expanded out into multiple indicators (the same way that regular glm() does it) and so you would actually have more than four priors to specify. If you're using factors let me know and I can clarify more if that would be helpful.
With rstanarm version 2.19.2 you might also want to add the autoscale=FALSE
argument to normal()
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:
iter = 100000: can I ask why so many iterations? It's certainly not wrong, but almost definitely a waste of time to run it that long. You may see advice like that in the Bayesian literature, but that's because for a long time the only MCMC algorithms available needed that many iterations (e.g., Gibbs sampling, Metropolis Hastings, and others) because of horrible autocorrelation in the Markov chains. However, the algorithms that Stan uses are particularly designed to explore the posterior distribution more efficiently and rarely require more than a few thousand iterations. The default of 2000 iterations per chain (1000 warmup + 1000 saved) is usually plenty for Stan to converge and if not it shouldn't require too many more than that. Were you increasing the iterations because you were getting convergence warnings?
chains = 4, cores = 5
: specifying more cores than chains doesn't currently help. It's not an error, but currently rstanarm will only use one core per chain. Stan does support multiple threads per chain, but that's not yet implemented in rstanarm.
Thank you very much! This, solved my issue. Also, thank you for the suggestions about the iterations.
Great, glad that helped!
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: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