'Trials ' missing in model description with brm

Hi!
I’m currently trying to model a GLMM with brms in R.

My dependent is a binary variable (sure_recognition, either 0= faslse or 1=true) which should be predicted by an interaction term of a prediction error (signedPE, ranging continously between -1 and 1) and a time delay (shockDelayTime, ranging continously between 0 and 10 seconds). I’d add subject ID as random effect. Every subject has mutiple trials.

The model looks as the following:

B1 ← brm(sure_recognition~
shockDelayTime*signedPE
+ (1|subj),
family = binomial(link=“logit”),
data = df)

Regarding the brms documentation, the model should be computed without any further specifications.
Unfortunately, I’m getting the following error message:
“Error: Specifying ‘trials’ is required for this model”

As mentioned, I do have the variable “trial” in my dataframe, but I think R wants me to specifiy anything else. I cannot find any clarification on the “trials”-variable online that has to be specified beforehand.

Can someone help me out?

Thanks a lot in advance and best,
Kaja

For a binary (true or false) dependent variable you are best off use the bernoulli distribution, not binomial. Binomial is for data where the dependent variable in each row is the number of “true” in a set of “trials”, in which case both numbers ned to be specified. Unrelated to your question, It would be a good idea to set a prior for this model.

1 Like

If you prefer to use the binomial likelihood for binary data, here’s how to use the trials() helper function for your use case:

B2 <- brm(
  sure_recognition | trials(1) ~ shockDelayTime * signedPE + (1|subj),
  family = binomial(link="logit"),
  data = df)

Since all of your data are binary, you can just set 1 within the trials() function, which tells brm() that each row in the sure_recognition vector is for a single Bernoulli trial. If you would like to try the Bernoulli likelihood, instead, it would look like this:

B3 <- brm(
  sure_recognition ~ shockDelayTime * signedPE + (1|subj),
  family = bernoulli(link="logit"),
  data = df)

In my experience, either approach is totally fine.

1 Like

Thanks, that solved my probem!

1 Like