dat <- budworm
dat <- dat[dat$dose %in% c(1,2), ]
dat$ntotal <- 5
dat
dat.a <- dat |>
binomial_to_bernoulli_data(ndead, ntotal, type="total")
dat.b <- dat |>
dplyr::mutate(nalive=ntotal-ndead) |> dplyr::select(-ntotal) |>
binomial_to_bernoulli_data(ndead, nalive, type="rest")
m0 <- glm(cbind(ndead, ntotal-ndead) ~ dose + sex, data=dat, family=binomial())
m1 <- glm(ndead / ntotal ~ dose + sex, data=dat, weight=ntotal, family=binomial())
ma <- glm(response ~ dose + sex, data=dat.a, family=binomial())
mb <- glm(response ~ dose + sex, data=dat.b, family=binomial())
dat.a$response
dat.b$response ## Not same and therefore the following do not match
all.equal(coef(m0), coef(ma))
all.equal(coef(m0), coef(mb))
all.equal(coef(m1), coef(ma))
all.equal(coef(m1), coef(mb))
Run the code above in your browser using DataLab