 # Adjusting prior for one level of a factor (rstanarm)

Simple reprex below.

``````library(rstanarm)

fruit = c(rep("apples", 20),
rep("oranges", 20),
rep("bananas", 20))

prices = c(rnorm(20, 1, .1),
rnorm(20, .9, .2),
rnorm(20, 2, .1))

df = data.frame(fruit = fruit,
prices = prices)

model <- stan_glm(prices ~ fruit, data = df)

new_data = data.frame(fruit = rep("bananas", 10))
samples <- posterior_predict(model, newdata = new_data)
mean(samples)
``````

I happen to have inside information that (a) the price of bananas is going to fall precipitously from \$2 to 50 cents and (b) the price of apples is going to increase from \$1 to \$2. I’d like to embed this information in my prior. My question is- how do I specify the prior for a single level of a factor?

Many thanks.

The baseline in that model is apples, so the coefficients are interpretable as the difference in the price of oranges or bananas compared to apples. You can specify a normal prior on all the coefficients with a vector of prior means and / or prior standard deviations with something like

``````prior = normal(location = c(1, -1), scale = c(1, 1.5), autoscale = FALSE)
``````

However,

that is information about the forecasted values of the variables in your model. I don’t see how that provides any additional information about the coefficients.