Here is a little script describing my problem.
I am fitting a logistic model in R using the mgcv package.
The dataset represent the occurrence of an event under certain conditions.
For this model, I need to weight each line of information.
library(mgcv)
set.seed(123)
n <- 100
x <- runif(n, 0, 1)
y <- rbinom(n, size = 1, prob = plogis(2 * x - 1))
y <- cbind(y, ifelse(y == 1, 0, 1)) # convert the response to a two column matrix
weights <- runif(n, 0, 1)
# Fit the binomial GAM with weights
mod <- gam(y ~ s(x), family = binomial, weights = weights/mean(weights))
# Use qq.gam (from mgcv)
qq.gam(mod)
But I get multiple warnings
1: In fam$qf(U, object$fitted.values, object$prior.weights, object$sig2) :
non-integer binomial denominator : incorrect quantiles
2: …
The fam$qf function is provided below. It uses the prior.weights from the model as the size parameter in the qbinom function. But the weights used in the model are defined as weights/mean(weights), so are by default not integer values (note that the normalization of the weights is suggested by Wood et al. to avoid changing the overall magnitude of the log likelihood, see “gam” help).
function (p, mu, wt, scale)
{
if (all.equal(wt, ceiling(wt)) != TRUE) {
wt <- ceiling(wt)
warning("non-integer binomial denominator: quantiles incorrect")
}
qbinom(p, wt, mu)/(wt + as.numeric(wt == 0))
}
Is there a way to obtain a correct QQplot from such kind of model?
Thanks