I am trying to fit a linear model in rstanarm using the hierarchical shrinkage prior. I do however get an error stating that location of the prior must be greater than 0.
Error: location > 0 is not TRUE
I am kind of surprised, since the hs()
prior does not have a location parameter. I have tried fitting the same model using a standar normal prior, and I get the same error, which does not make much sense to me, since 0 centered priors are the default option.
I have looked at the stan_lm.R
and stan_lm.fit.R
files in the github repositories, and I have not been able to find the source of the this error.
Below I include code to replicate the error, please note that the choice of priors in this example might not be very adecuate, but the sole purpose of this pice of code is to illustrate the error I am getting:
library(rstanarm)
library(tidyverse)
library(MASS)
nObs <- 400
x <- mvrnorm(n = nObs, mu = c(0, 0, 0),
diag(c(0.5, 1, 2)))
y <- (x %*% c(0.3, 0.4, 0.5)) + rnorm(n = nObs, 0, 1)
fullData <- cbind(y, x) %>% as.data.frame
model0 <- stan_lm(y ~ -1 + x, data = fullData,
prior = normal(location = 0, scale = 1))
model1 <- stan_lm(y ~ -1 + x, data = fullData,
prior = hs(df = 1, global_df = 1, global_scale = 0.01,
slab_df = 4, slab_scale= 2.5))
Try using stan_glm
to fit your normal linear model. The stan_lm
function requires the prior to be specified on R^2, not the regression coefficients - hence the location must be >0.
See the documentation for the prior
parameter in stan_lm
for more details.