2

In R's glm() function you can fit a logistic regression (with family = binomial) by using a "column specification" of the response variable like so:

glm(cbind(success, (n - sucess)) ~ 1, family = binomial, ...)

The documentation of brmsformula (under additional response information) states, that in brm() the same can be achieved with:

brm(success | trials(n) ~ 1, family = binomial, ...)

This seems to work as can be seen from the following (admittedly rather silly) example:

set.seed(1)
n_rows = 10
success = abs(round(rnorm(n_rows), 1) * n_rows)
n = success * 2
data = data.frame(success, n)

library(brms)
model = brm(success | trials(n) ~ 1, 
            data = data,
            family = binomial("logit"))

However, when I increase n_rows, say to 100, I get the following error message:

Error: Family 'binomial' requires integer responses.

Can somebody make sense of why that is? In glm the data with n_rows = 100 works fine.

(Obviously my real data (where the error occurs as well) looks different. I just managed to recreate it like this.)

Any help is very welcome!

MrMax
  • 393
  • 1
  • 2
  • 10
  • 1
    try explicitly coercing the variables to integer – user20650 Sep 23 '19 at 12:33
  • you were right. it was as easy as that. specifying data$success and data$n as.integer and avoiding zeros in the data$n column solved it. thanks a lot! – MrMax Sep 23 '19 at 12:43

0 Answers0