I want to fit GLMM Poisson model counts. I have 121 subjects (subject
), I observe 8 Poisson counts (count
) per subject: they correspond to 2 types of events (event
) x 4 periods (period
).
'data.frame': 968 obs. of 4 variables:
$ count : num 4 0 2 3 3 0 1 0 8 14 ...
$ subject: num 1 1 1 1 1 1 1 1 2 2 ...
$ event : Factor w/ 2 levels "call","visit": 2 2 2 2 2 2 2 2 1 1 ...
$ period : Factor w/ 4 levels "period_1","period_2",..: 1 2 3 4 1 2 3 4 1 2 ...
What I want:
subject
, (2) subject:visit
, (3) subject:event
.subject
, (2) subject:visit
, (3) subject:event
, respectively,What I managed to get:
I believe I am setting the model formula properly, and I am setting the desired priors for fixed effect parameters:
## define some priors
prior <- c(prior_string("normal(0,10^3)", class = "b"),
prior_string("normal(0,10^3)", class = "b", coef = "eventvisit"),
prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_2"),
prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_3"),
prior_string("normal(0,10^3)", class = "b", coef = "eventvisit:periodperiod_4"),
prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_2"),
prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_3"),
prior_string("normal(0,10^3)", class = "b", coef = "periodperiod_4"))
## fit model
fit1 <- brm(count ~ event + period + event:period + (1|subject) + (0 + event|subject) + (0 + period|subject),
data = data.long, family = poisson(),
prior = prior,
warmup = 1000, iter = 4000, chains = 4,
cores = 7)
What I struggle with:
subject
, (2) subject:visit
, (3) subject:event
, respectively,With regard to what you want: Could you please explain in more detail what you want with subject:visit
and subject:event
? Currently, I cannot tell whether your model is correctly specified for your purpose.
With regard to the priors:
prior_string("normal(0,10^3)", class = "b")
, there is no need to specifiy that prior again for each coefficient. Setting it globally for the whole prior class is sufficient. Note that, given the scale of your response and predictor variables, normal(0, 1000) is so wide that it has practically no influence. You migh as well just leave it out.normal(0, sigma_x)
priors are set automatically for all random effects terms. No need to worry about them.class = "sd"
. For instance prior_string("cauchy(0, 5)", class = "sd")
. I explicitely encourage you not to use uniform priors in particular because they have a hard upper bound for a parameter (standard deviation), which has not theoretical upper bound.