I want to incorporate weights into the likelihood to do what the svyglm does with weights.
According to Jeremy Miles and elsewhere, svyglm function uses weights to "weight the importance of each case to make them representative (to each other, ...)".
Here is my data:
(dat <- data.frame(
A = c(1, 1, 0, 0), B = c(1, 0, 1, 0),
Pass = c(278, 100, 153, 79), Fail = c(743, 581, 1232, 1731), Weights= c(3, 1, 12, 3)
))
Here is my likelihood function:
ll <- function (b0, b1, b2, b3) {
odds <- exp(b0) * (1 + b1 * dat$A + b2 * dat$B + b3 * dat$A * dat$B)
-sum(dbinom(
x = dat$Pass, size = rowSums(dat[, 3:4]),
prob = odds / (1 + odds), log = TRUE))
}
