Response:
$$y_i - \hat\mu_i$$
response residuals are inadequate for assessing a fitted glm, because GLMs are based on distributions where (in general) the variance depends on the mean.
Pearson:
The most direct way to handle the non-constant variance is to divide
it out:
$$ \frac{y_i - \hat\mu_i}{\sqrt{V(\mu_i)|_{\hat\mu_i}}}$$
where $V()$ is the (GLM) variance function ($Var(y_i) = a(\phi)*V(\mu_i)$)
Under "Small dispersion asymptotics" conditions, the Pearson residuals have an approximate normal distribution.
Deviance: $$sign(y_i-\hat\mu_i)*\sqrt{d_i}$$ where $d_i$ is the unit deviance, i.e. $d_i = 2(t(y_i,y_i)-t(y_i,\hat\mu_i))$
The deviance statistic (sum of squared unit-deviances) has an approximate chi-square distribution (when the saddlepoint approximation applies and under "Small dispersion asymptotics" conditions). Under these same conditions, the deviance residuals have an approximate normal distribution.
Working:
$$z_i - \eta_i $$
where $z_i$ are the working responses $\eta_i + \frac{d\eta_i}{d\mu_i}(y_i-\hat\mu_i)$ and $\eta_i$ is the linear predictor. Meaning you get that the residual is $\frac{d\eta_i}{d\mu_i}(y_i-\hat\mu_i)$.
The model coefficients are fitted using Fisher scoring algorithm / Iterative Reweighted Least Square (IRLS). And it can be shown that each iteration of this algorithm is equivalent to doing ordinary least-squares on the working responses as defined here.
To test the link function - plotting the linear predictor against the working responses should come out linear if the right link function was used.
Partial:
$$z_i - \eta_i + X^*\beta$$
where $X^*$ is the centered $X$. Partial residuals can be used to determine if a covariate/predictor is on an inappropriate scale.
Quantile:
$$\Phi^{-1}(F(y_i))$$
Where $F(y_i)$ is the CDF of $y_i$, and $\Phi^{-1}$ is the quantile function of standard normal (inverse CDF). For discrete $y_i$'s you take $u \sim Unif(F(y_i-1), F(y_i))$ and $\Phi^{-1}(u)$.
Here is an example code to calculate these residuals:
Y = c(0,0,0,0,1,1,1,1,1)
x1 = c(1,2,3,1,2,2,3,3,3)
x2 = c(1,0,0,1,0,0,0,0,0)
fit = glm(y ~ x1 + x2, family = 'binomial')
lp = predict(fit)
mu = exp(lp)/(1+exp(lp))
# manually calculating the 1st response residual
resid(fit, type="response")[1]
Y[1] - mu[1]
# manually calculating the 1st pearson residual
resid(fit, type="pearson")[1]
(Y[1]-mu[1]) / sqrt(mu[1]*(1-mu[1]))
# manually calculating the 1st deviance residual
resid(fit, type="deviance")[1]
sqrt(-2*log(1-mu[1]))*sign(Y[1]-mu[1])
# manually calculating the 1st working residual
resid(fit, type="working")[1]
(Y[1]-mu[1]) / (mu[1]*(1-mu[1]))
# manually calculating the 1st partial residual
resid(fit, type="partial")[1,1]
(Y[1]-mu[1]) / (mu[1]*(1-mu[1])) + fit$coefficients[2]*(x1[1] - mean(x1))
resid(fit, type="partial")[1,2]
(Y[1]-mu[1]) / (mu[1]*(1-mu[1])) + fit$coefficients[3]*(x2[1] - mean(x2))
# manually calculating the 1st quantile residual
library(statmod)
qresid(fit)[1] # results are random (uniformly), so won't come the same
a = pbinom(Y[1]-1, 1, mu[1])
b = pbinom(Y[1], 1, mu[1])
qnorm(runif(1, a, b)) # results are random (uniformly), so won't come the same
n = 10000
mean(replicate(n, qresid(fit)[1]))
mean(qnorm(runif(1000, a, b))) # should be close
For more information I suggest you check this book: Generalized Linear Models With Examples in R:
working response - section 6.3, working residuals - section 6.7, response residuals - section 8.3.1, pearson residuals - section 8.3.2, deviance residuals - section 8.3.3, partial residuals - section 8.7.3
So,
will sum of squared residuals provide a meaningful measure of model fit ?
For Deviance/Pearson - I think so.
But more generally inspecting the residuals can be a bit tricky. In many cases neither the Pearson nor deviance residuals can be guaranteed to have distributions close to normal, especially for discrete distributions. "Small dispersion asymptotics" need to hold (see section 7.5 in the book), so some rule of thumbs are used. For Binomial distributions, and the deviance residual $\min(n_i y_i) > 3$ as well as $\min(n_i(1-y_i)) > 3$. There are also the Quantile Residuals that can be used when these conditions are not met. Check section 8.3.4 of the book.
binnedplot
function in the R package arm gives a very helpful plot of residuals. It's described nicely on p.97-101 of Gelman and Hill 2007. $\endgroup$