Newbie to brms here. I am trying to implement an model where the intercepts of the binomial regression depends on the value of corresponding index value of the same observation. It looks like this in rethinking package:
m11.4 <- ulam(
alist(
pulled_left~dbinom(1, p),
logit(p) <- a[actor] + b[treatment],
a[actor] ~ dnorm(0, 1.5),
b[treatment] ~ dnorm(0, 0.5)
),
data = dat_list, chains = 4,log_lik = T
)
this could be trans-compiled into stan code as below:
data{
int pulled_left[504];
int treatment[504];
int actor[504];
}
parameters{
vector[7] a;
vector[4] b;
}
model{
vector[504] p;
b ~ normal( 0 , 0.5 );
a ~ normal( 0 , 1.5 );
for ( i in 1:504 ) {
p[i] = a[actor[i]] + b[treatment[i]];
p[i] = inv_logit(p[i]);
}
pulled_left ~ binomial( 1 , p );
}
generated quantities{
vector[504] log_lik;
vector[504] p;
for ( i in 1:504 ) {
p[i] = a[actor[i]] + b[treatment[i]];
p[i] = inv_logit(p[i]);
}
for ( i in 1:504 ) log_lik[i] = binomial_lpmf( pulled_left[i] | 1 , p[i] );
}
Just wondering how should I do the same in brms? which of the below code would work?
option 1:
m11.4_brms <- brm(data = dat_list, family = binomial,
pulled_left | trials(1) ~ 0 + (1|treatment) + (1|actor),
prior = c(
prior(normal(0, 1.5), class = sd, coef = "Intercept", group = "actor"),
prior(normal(0, 0.5), class = sd, coef = "Intercept", group = "treatment")
)
)
Option 2:
m11.4_brms2 <- brm(data = dat_list, family = binomial,
pulled_left | trials(1) ~ 0 + factor(treatment) + factor(actor),
prior = prior(normal(0, 1.5), class = b)
)
Option 1 yields similar results to the rethinking model, but is it a multi-level model?
Option 2’s results are different and the intercept is hard to interpret, however it feels spiritually closer to the original?
Could someone help illustrate the syntax for indexing variable in this context?
Thanks!