Repeated measure logistic regression

hello

dear all

I want to perform a bayesian logistic regression on my repeated measure data. I have a problem with specifying the formula and specifying random effects. would you please help me to fix that?
i want to have a random effect based on participant id.
yielding (0,1) is my response variable and TTA is my predictor and I want have a random effect based on parti_id
i used this formula but I get an error:
brm(data = df2,
family = binomial,
yielding ~ 1 + TTA + (1 | parti_id),
prior = c(prior(normal(0, 2), class = Intercept),
prior(normal(0, 2), class = b),
prior(normal(0, 2), class = sd)),
iter = 2500, warmup = 500, chains = 4, cores = 4,
seed = 21)

I get this error:
Warning: Using ‘binomial’ families without specifying ‘trials’ on the left-hand side of the model formula is deprecated.Only 2 levels detected so that family ‘bernoulli’ might be a more efficient choice.

do you have any idea about this? very much appreciated your response.

Hi @ali

Welcome to the forum. That’s not an error, but a warning telling you that you might find the HMC sampling to be more efficient if you specify

brm(
  data = df2,
  family = bernoulli,  # bernoulli instead of binomial
  yielding ~ 1 + TTA + (1 | parti_id),
  prior = c(
    prior(normal(0, 2), class = Intercept),
    prior(normal(0, 2), class = b),
    prior(normal(0, 2), class = sd)
  ),
  iter = 2500, warmup = 500, chains = 4, cores = 4,
  seed = 21
)

I also recommend using more iterations for the warmup phase so that the final samples start off clean. The default of using half of samples for warmup makes sense usually.

By the way, when you want to show some code, it is much easier to read if you wrap it in three backticks, like this

```
# code goes here
```

Hope that helps.

2 Likes

thanks @matti

I really appreciate your help. it worked!

yes, I will follow your advice next time I ask questions here.

best,
Ali

@matti’s suggestion to use the Bernoulli likelihood is great. If you’d like to stay with the binomial likelihood, you can use code like this:

brm(
  data = df2,
  family = binomial,
  yielding | trials(1) ~ 1 + TTA + (1 | parti_id),
  prior = c(
    prior(normal(0, 2), class = Intercept),
    prior(normal(0, 2), class = b),
    prior(normal(0, 2), class = sd)
  ),
  iter = 2500, warmup = 500, chains = 4, cores = 4,
  seed = 21
) 

Notice the | trials(1) syntax on the left side of the model formula. That’s what the warning message was referring to with the phrase: “Using ‘binomial’ families without specifying ‘trials’ on the left-hand side of the model formula is deprecated.” With the | trials(1) syntax, you are explicitly telling brm() each row in the yielding variable corresponds to a single Bernoulli trial.

Great to hear it helped. If you don’t mind you can mark the post as the solution to help others find the “right” answer quickly in the future :)

1 Like

If you have discrete levels of TTA it will be much faster to compute the sum of yielding (by TTA, parti_id) and then fit the model as a binomial.