# Re: [Rd] Standardized Pearson residuals

From: Brett Presnell <presnell_at_stat.ufl.edu>
Date: Mon, 14 Mar 2011 23:40:29 -0400

Thanks Peter. I have just a couple of minor comments, and another possible feature request, although it's one that I don't think will be implemented.

> On Mar 14, 2011, at 22:25 , Brett Presnell wrote:
>
>>
>> Is there any reason that rstandard.glm doesn't have a "pearson" option?
>> And if not, can it be added?
>
> Probably... I have been wondering about that too. I'm even puzzled why
> it isn't the default. Deviance residuals don't have quite the
> properties that one might expect, e.g. in this situation, the absolute
> residuals sum pairwise to zero, so you'd expect that the standardized
> residuals be identical in absolute value
>
>> y <- 1:4
>> r <- c(0,0,1,1)
>> c <- c(0,1,0,1)
>> rstandard(glm(y~r+c,poisson))
> 1 2 3 4
> -0.2901432 0.2767287 0.2784603 -0.2839995
>
> in comparison,
>
>> i <- influence(glm(y~r+c,poisson))
>> i\$pear.res/sqrt(1-i\$hat)
> 1 2 3 4
> -0.2817181 0.2817181 0.2817181 -0.2817181
>
> The only thing is that I'm always wary of tampering with this stuff,
> for fear of finding out the hard way why thing are the way they
> are....

>> Agresti's "Introduction to Categorical Data Analysis (2nd edn)" and
>> deviance residuals are not used in the text. For now I'll just provide
>> the students with a simple function to use, but I prefer to use R's
>> native capabilities whenever possible.
>
> Incidentally, chisq.test will have a stdres component in 2.13.0 for
> much the same reason.

BTW, as I go along I'm trying to collect a lot of the datasets from the examples and exercises in the text into an R package ("icda"). It's far from complete and what is there needed tidying up, but I hope to eventually to round it into shape and put it on CRAN, assuming that Agresti approves and that there are no copyright issues.

>> I think something along the following lines should do it:
>>
>> rstandard.glm <-
>> function(model,
>> infl=influence(model, do.coef=FALSE),
>> type=c("deviance", "pearson"), ...)
>> {
>> type <- match.arg(type)
>> res <- switch(type, pearson = infl\$pear.res, infl\$dev.res)
>> res <- res/sqrt(1-infl\$hat)
>> res[is.infinite(res)] <- NaN
>> res
>> }

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 15 Mar 2011 - 03:44:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Mar 2011 - 12:50:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.