I’m stuck on setting an informative prior to a brms bernoulli model using logit link. Possibly the logit link causes confusion for me.
Data
I generated 5-year data. Each year, males proportion increases by ~10 percentage points.
library(tidyverse)
n = 100
a = tibble(sex = rep(c("m", "m", "m", "m", "m", "m", "m", "f", "f", "f"), length.out = n), year = rep(c(3, 4, 5), length.out = n))
b = tibble(sex = rep(c("m", "m", "m", "m", "m", "m", "f", "f", "f", "f"), length.out = n), year = rep(c(2, 3, 4), length.out = n))
c = tibble(sex = rep(c("m", "m", "m", "m", "m", "f", "f", "f", "f", "f"), length.out = n), year = rep(c(1, 2, 3), length.out = n))
d = tibble(sex = rep(c("m", "m", "m", "m", "f", "f", "f", "f", "f", "f"), length.out = n), year = rep(c(0, 1, 2), length.out = n))
e = rbind(a, b)
f = rbind(e, c)
df = rbind(f, d)
df = df %>% mutate(sex = as.factor(sex))
df %>% ggplot(aes(year, fill = sex)) + geom_bar(position = "fill") + ylab("proportion") + scale_fill_manual(values = c("red", "skyblue"))
I’d like to run a model as follows
m = brm(sex ~ year, family = "bernoulli", data = df, sample_prior = TRUE, prior = prior)
but how to code an informative prior for the model?
I tried the following that did not work. I assumed that each year males proportion would increase by 10 percentage points.
prior = c(set_prior("normal(10, 5)", class = "b", coef = "year"))
This gives highly wide (non-informative) prior for my model.
m %>% posterior_samples() %>% ggplot() + geom_density(aes(b_year), color = "black") + geom_density(aes(prior_b_year), color = "red") + xlab("b_year (black) and prior_b_year (red)")
How should I code an informative prior for such model?