binned_residuals() for checking linearity of the logit #941
|
I'm using performance::binned_residuals(model, term = "x") to check the linearity of the logit assumption for a continuous predictor. In a simulation where the assumption is met, the default residuals = "deviance" produces a clear trend in average residuals across the predictor's range. This looks like a potential problem plot is meant to detect, but it's a false positive here since the model is correctly specified. Switching to residuals = "response" removes the drift. Do you all have a recommendation between the deviance vs. response residual type for checking linearity here? I think Gelman used response as far as I could tell. thanks! library(performance)
set.seed(1)
n <- 5000
x <- runif(n, 0, 10)
logit_true <- -2 + 0.4 * x
y <- rbinom(n, 1, plogis(logit_true))
df <- data.frame(x = x, y = y)
model <- glm(y ~ x, data = df, family = binomial)
# Default: deviance residuals
plot(binned_residuals(model, term = "x")) # Response residuals
plot(binned_residuals(model, term = "x", residuals = "response"))Created on 2026-08-25 with reprex v2.1.1 |
Replies: 3 comments
|
In the Gelman/Hill book, and in the documentation, it says:
However, the example from But observed minus expected would indeed be library(performance)
set.seed(1)
n <- 5000
x <- runif(n, 0, 10)
logit_true <- -2 + 0.4 * x
y <- rbinom(n, 1, plogis(logit_true))
df <- data.frame(x = x, y = y)
model <- glm(y ~ x, data = df, family = binomial)
arm::binnedplot(predict(model), resid(model), sqrt(n))Created on 2026-08-26 with reprex v2.1.1 |
|
Got it - that's helpful thanks. I was going a little crazy trying to understand why the deviance residuals showed this sort of bias when the response residuals and simulated residuals from DHARMa did not. I'll use the observed - expected. |
|
The default has changed now: Will be on cran soon, I guess |



In the Gelman/Hill book, and in the documentation, it says:
However, the example from
arm::binnedplot()usesresid(), which defaults to deviance residuals.But observed minus expected would indeed be
"response". We should probably change the default, especially since you have a nice simulation example that shows this.Created on 2026-08…