How to calculate partial residuals by hand?

KNR

New Member
#1
Code for GLM Poisson regression (R):

Code:
library(datasets) mydata <- warpbreaks
poisson_mod <- glm(breaks ~ wool + tension, mydata, family = poisson())
Gives:
Call:  glm(formula = breaks ~ wool + tension, family = poisson(link = "log"),
data = mydata)

Coefficients:
(Intercept)        woolB     tensionM     tensionH
3.6920      -0.2060      -0.3213      -0.5185

Degrees of Freedom: 53 Total (i.e. Null);  50 Residual
Null Deviance:    297.4
Residual Deviance: 210.4 AIC: 493.1
The partial residuals for the k-th covariate in a GLM model:
Schermata 2021-12-28 alle 10.05.00.png

Where r^W are the working residuals. So in my case:
Code:
residuals(poisson_mod, type = 'partial')[1,1]
[1] -0.2490071
Should be equal to:
Code:
residuals(poisson_mod, type = 'working')[1] + exp(coef(poisson_mod)[1] + coef(poisson_mod)[2]*mydata$breaks[1])
-0.1625714
Which is not. Why? What am I doing wrong or misunderstanding?