2
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

library(DHARMa)

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)
plot(res)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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