[R] chisq.test(): standardized (adjusted) Pearson residuals

David Winsemius dwinsemius at comcast.net
Sat Aug 20 19:12:16 CEST 2011


On Aug 20, 2011, at 12:57 PM, peter dalgaard wrote:

>
> On Aug 20, 2011, at 18:04 , Stephen Davies wrote:
>
>> As for "$stdres," that would be wonderful, but
>> as you can see from the above list of attributes, it's not one of  
>> the 8
>> returned. What am I missing?
>
> An upgrade, most likely.

Whoosh. Sometimes I am simply clueless. I didn't notice that 'stdres'  
was missing from the names in Stephen's output. Laura Thompson has a  
very nice R/S accompaniment to Agresti's "Categorical Data Analysis"  
text and she shows how to adjust the Pearson residuals to make them  
"standardized". What follows is directly from pages 37-38 of her work:

#--------------------------------------------------#
resid.pear <- residuals(fit.glm, type = "pearson")

Note that the sum of the squared Pearson residuals equals the Pearson  
chi-squared statistic:

sum(resid.pear^2)
[1] 69.11429

To get the standardized residuals, just modify resid.pear according to  
the formula on p. 81 of Agresti.

ni<-rowSums(table.3.2.array) # row sums

nj<-colSums(table.3.2.array) # column sums
n<-sum(table.3.2.array)  # total sample size
resid.pear.mat<-matrix(resid.pear, nc=3, byrow=T,  
dimnames=list(c("<HS","HS or JH",
"Bachelor or Grad"),c("Fund", "Mod", "Lib")))

n*resid.pear.mat/sqrt(outer(n-ni,n-nj,"*") ) # standardized Pearson  
residuals

                       Fund        Mod       Lib
              <HS  4.534062 -2.5520482 -1.941537
         HS or JH  2.552988  1.2859745 -3.994669
Bachelor or Grad -6.806638  0.7007539  6.250329

#--------------------------------------------------#

You can also look at the code (once you upgrade) and the method in R  
is quite similar, although the R codes calcualtes the stdres values  
separately rather than adjusting the Pearson residuals

>
> -- 
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list