Hi,
Apologies if I don’t use the correct terminology. I’m trying to build a multi-level model where the number of trials is a variable. Probably easier to explain in formula:
Code to create test data:
fdata = data.frame(t = runif(100, min = 0 , max = 15))
fdata$log_t = log(fdata$t)
fdata$n= rpois(100 , fdata$t * rnorm(100 , mean = 3, sd = 1) )
fdata$y= rbinom(n = 100 , size = fdata$n , prob = 0.8 )
I’ve tried this code:
b_mod <-
brm(data = fdata,
family = binomial,
bf(y | trials(n) ~ 1 ,
n ~ 1 + offset(log_t) , nl = TRUE),
prior = c(prior(normal(0, 1), class = Intercept),
prior(normal(0, 1), nlpar = b)),
iter = 2000, warmup = 1000, cores = 4, chains = 4,
seed = 11)
But I get the following error:
“Error: The parameter ‘n’ is not a valid distributional or non-linear parameter. Did you forget to set ‘nl = TRUE’?”
which makes me think that I can’t have the number of trials as part of the model ?