[R] residuals and glm

2007-02-22 Thread Martin Olivier
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@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.


Re: [R] residuals and glm

2007-02-22 Thread David Barron
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 [EMAIL PROTECTED] 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@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

__
R-help@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.


Re: [R] residuals and glm

2007-02-22 Thread Prof Brian Ripley
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,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] residuals and glm

2007-02-22 Thread Frank E Harrell Jr
David Barron wrote:
 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

And in the Design package's lrm and residuals.lrm function (called by 
resid(fit)) you can get partial residuals that when smoothed estimate 
covariate effects.  I do prefer direct modeling instead of looking at 
any of the residuals though, e.g., adding nonlinear or interaction terms 
to logistic models.  Usually I find that residuals in simple binary 
logistic models are most useful in checking for overly influential 
observations.

Frank Harrell

 
 On 22/02/07, Martin Olivier [EMAIL PROTECTED] 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@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.

 
 


-- 
Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University

__
R-help@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.