Hi all, I have some problems to compute the residuals from a glm model with binomial distribution. Suppose I have the following result : resfit<-glm(y~x1+x2,weights=we,family=binomial(link="logit")) Now I would like to obtain the residuals . the command residuals(resfit) and the vector resfit$residuals give different results, and they do not correspond to residuals E(yi)-yi (that is resfit$fitted-resfit$y) so, I would like to know what formula is applied to compute these residuals. And moreover, if I want to compute the standardized residuals, what is the right command from the glmfit result. Is it (resfit$fitted-resfit$y)/sqrt(1/resfit$prior*resfit$fitt*(1-resfit$fitt)) ?? Thanks for your help, Olivier.
You really need to look at ?glm and ?residuals.glm. resfit$residuals are the *working* residuals, which are not typically very useful in themselves. Far better to use the extractor function. This enables you to obtain a number of different types of residuals, but the default (and therefore the type you have obtained) are deviance residuals. You can also specify other types, such as pearson residuals. Hope this helps. David On 22/02/07, Martin Olivier <olivier.martin at avignon.inra.fr> wrote:> Hi all, > > I have some problems to compute the residuals from a glm model with > binomial distribution. > > Suppose I have the following result : > resfit<-glm(y~x1+x2,weights=we,family=binomial(link="logit")) > > Now I would like to obtain the residuals . > the command residuals(resfit) and the vector resfit$residuals give > different > results, and they do not correspond to residuals E(yi)-yi (that is > resfit$fitted-resfit$y) > > so, I would like to know what formula is applied to compute these > residuals. > And moreover, if I want to compute the standardized residuals, what is the > right command from the glmfit result. > Is it > (resfit$fitted-resfit$y)/sqrt(1/resfit$prior*resfit$fitt*(1-resfit$fitt)) ?? > > > Thanks for your help, > Olivier. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- ================================David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP
On Thu, 22 Feb 2007, Martin Olivier wrote:> I have some problems to compute the residuals from a glm model with > binomial distribution. > > Suppose I have the following result : > resfit<-glm(y~x1+x2,weights=we,family=binomial(link="logit")) > > Now I would like to obtain the residuals . the command residuals(resfit) > and the vector resfit$residuals give different results, and they do not > correspond to residuals E(yi)-yi (that is resfit$fitted-resfit$y)?residuals.glm should help you, but note that residuals are always conventionally (observed - fitted), not as you give. ?glm tells you what resfit$residuals is, and it seems to be not what you think it is.> so, I would like to know what formula is applied to compute these > residuals. And moreover, if I want to compute the standardized > residuals, what is the right command from the glmfit result. Is it > (resfit$fitted-resfit$y)/sqrt(1/resfit$prior*resfit$fitt*(1-resfit$fitt)) > ??See ?rstandard and print(rstandard.glm). -- 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