0

Is there an issue with the likelihood computation of the binomial model fit with glm when using cbind or am I missing something. See below for reproducible example:

set.seed(123)
n <- 100
sze <- 5
x <- rnorm(n, 0, 1)
p <- binomial()$linkinv(x)
y <- rbinom(n, sze, p)
tot <- rep(sze, n)
# Fit binomial model on grouped data
modA <- glm(cbind(y, tot - y) ~ x, family = binomial())
modA
# Ungroup the bernoulli trials
xy <- lapply(1:n, function(i) cbind(c(rep(1,y[i]), rep(0,sze-y[i])), c(rep(x[i], sze))))
xy <- do.call(rbind, xy)
# Fit binomial model on ungrouped 0/1 data
modB <- glm(xy[,1] ~ xy[,2], family = binomial())
modB
logLik(modA)
logLik(modB)

If I'm not mistaken, both models should be the same. Coefficient estimates are exactly the same. However, the log likelihood is different.

user2506086
  • 503
  • 2
  • 10

0 Answers0