[R] residuals of glm

Yuan Jian jayuan2008 at yahoo.com
Mon Sep 29 12:11:15 CEST 2014


Hello,
I found the residuals of glm is not the same as calculated manually.
 >y=c(12,14,33,50,67,74,123,141,165,204,253,246,240)
> t=1:13
> m1=glm(y~t+I(t^2),family=poisson(link="log"))
> coefficients(m1)[1]+coefficients(m1)[2]*log(t)+coefficients(m1)[3]*log(t^2)
 [1] 1.901459 2.257258 2.465388 2.613058 2.727600 2.821188 2.900315 2.968858
 [9] 3.029318 3.083400 3.132324 3.176988 3.218075
> log(y)-m1$residuals
       1        2        3        4        5        6        7        8 
2.434906 2.890062 3.369962 3.775366 4.146170 4.456127 4.745377 4.982733 
       9       10       11       12       13 
5.174013 5.326826 5.429551 5.499618 5.521138 


i hope the last two sentences have the same result. could anyone help me out?
thanks
Jay

	[[alternative HTML version deleted]]



More information about the R-help mailing list