Dear R Users, I suppose this is a school boy question, but here it is anyway. I'm trying to re-create the residuals for a poisson GLM with simulated data; x<-rpois(1000,5) model<-glm(x~1,poisson) my.resids<-(log(x)- summary(model)$coefficients[1]) plot(my.resids,residuals(model)) This shows that my calculated residuals (my.resids) are not the same as residuals(model). p 65 of Annette Dobson's book says that GLM (unstandardised) residuals are calculated by analogy with the Normal case. So where am I going wrong? Thanks for your attention. Martin. Martin Hoyle, School of Life and Environmental Sciences, University of Nottingham, University Park, Nottingham, NG7 2RD, UK Webpage: http://myprofile.cos.com/martinhoyle
As ?residuals.glm reveals, it's got an argument type:
type: the type of residuals which should be returned. The
alternatives are: `"deviance"' (default),
`"pearson"',
`"working"', `"response"', and
`"partial"'.
You calculated "response" residuals, R gives "deviance"
residuals
by default. The different types are covered by most books on general
linear models.
HTH
Thomas
> -----Original Message-----
> From: Martin Hoyle [mailto:plxmh at nottingham.ac.uk]
> Sent: 27 August 2003 17:01
> To: r-help at stat.math.ethz.ch
> Subject: [R] Basic GLM: residuals definition
>
>
> Dear R Users,
>
> I suppose this is a school boy question, but here it is
> anyway. I'm trying to re-create the residuals for a poisson
> GLM with simulated data;
>
> x<-rpois(1000,5)
> model<-glm(x~1,poisson)
> my.resids<-(log(x)- summary(model)$coefficients[1])
> plot(my.resids,residuals(model))
>
> This shows that my calculated residuals (my.resids) are not
> the same as residuals(model).
> p 65 of Annette Dobson's book says that GLM (unstandardised)
> residuals are calculated by analogy with the Normal case.
> So where am I going wrong?
>
> Thanks for your attention.
>
> Martin.
>
>
> Martin Hoyle,
> School of Life and Environmental Sciences,
> University of Nottingham,
> University Park,
> Nottingham,
> NG7 2RD,
> UK
> Webpage: http://myprofile.cos.com/martinhoyle
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
---
Thomas Hotz
Research Associate in Medical Statistics
University of Leicester
United Kingdom
Department of Epidemiology and Public Health
22-28 Princess Road West
Leicester
LE1 6TP
Tel +44 116 252-5410
Fax +44 116 252-5423
Division of Medicine for the Elderly
Department of Medicine
The Glenfield Hospital
Leicester
LE3 9QP
Tel +44 116 256-3643
Fax +44 116 232-2976
On Wed, 27 Aug 2003, Martin Hoyle wrote:> Dear R Users, > > I suppose this is a school boy question, but here it is anyway. I'm trying to re-create the residuals for a poisson GLM with simulated data; > > x<-rpois(1000,5) > model<-glm(x~1,poisson) > my.resids<-(log(x)- summary(model)$coefficients[1]) > plot(my.resids,residuals(model)) > > This shows that my calculated residuals (my.resids) are not the same as residuals(model). > p 65 of Annette Dobson's book says that GLM (unstandardised) residuals are calculated by analogy with the Normal case. > So where am I going wrong?Not reading the help page. Hint: what is the default for the type argument for the glm method for residual? A much better reference for this is Davison, A.~C. and Snell, E.~J. (1991) Residuals and diagnostics. \newblock Chapter~4 of \cite{Hinkley.ZZ.91}. Hinkley, D.~V., Reid, N. and Snell, E.~J. eds (1991) \emph{Statistical Theory and Modelling. In Honour of Sir David Cox, {FRS}}. \newblock London: Chapman \& Hall. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595