I am running a glm with a binary response variable (0 or 1) in R, one of my significant predictors is continuous and the other is categorical. How would I get the residuals for this model, especially with the response variable being binary?


You can use the DHARMa package, which implements the idea of randomized quantile residuals by Dunn and Smyth (1996).

Essentially, the idea is to simulate new data from the fitted model, and compare to the observed data. Details see https://cran.r-project.org/web/packages/DHARMa/vignettes/DHARMa.html

Here an example with a missing quadratic effect in the glm, which shows up in the right plot.


dat = createData(replicates = 1, sampleSize = 300, intercept = -3,
           fixedEffects = 1, quadraticFixedEffects = 20, 
           randomEffectVariance = 0, family = binomial())

fit = glm(observedResponse ~ Environment1 , data = dat, family = binomial)
res = simulateResiduals(fit)

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.