Skip to content
Prev 269176 / 398502 Next

chisq.test(): standardized (adjusted) Pearson residuals

On Aug 20, 2011, at 12:04 PM, Stephen Davies wrote:

            
The names attribute let's you know what characters to use if you want  
to access values in a list. Unless you are doing programming  
attributes is not a particular useful function. It is much more common  
to access the names attribute with the  `names` function:

 > names(Xsq)
[1] "statistic" "parameter" "p.value"   "method"    "data.name"  
"observed"  "expected"
[8] "residuals" "stdres"

So "stdres" is not an attribute but rather one value in a particular  
attribute called "names".

You would get (much) more information by using str on the htest object  
as below:

 > str(Xsq)
List of 9
  $ statistic: Named num 30.1
   ..- attr(*, "names")= chr "X-squared"
  $ parameter: Named num 2
   ..- attr(*, "names")= chr "df"
  $ p.value  : num 2.95e-07
  $ method   : chr "Pearson's Chi-squared test"
  $ data.name: chr "M"
  $ observed : table [1:2, 1:3] 762 484 327 239 468 477
   ..- attr(*, "dimnames")=List of 2
   .. ..$ gender: chr [1:2] "M" "F"
   .. ..$ party : chr [1:3] "Democrat" "Independent" "Republican"
  $ expected : num [1:2, 1:3] 704 542 320 246 534 ...
   ..- attr(*, "dimnames")=List of 2
   .. ..$ gender: chr [1:2] "M" "F"
   .. ..$ party : chr [1:3] "Democrat" "Independent" "Republican"
  $ residuals: table [1:2, 1:3] 2.199 -2.505 0.411 -0.469 -2.843 ...
   ..- attr(*, "dimnames")=List of 2
   .. ..$ gender: chr [1:2] "M" "F"
   .. ..$ party : chr [1:3] "Democrat" "Independent" "Republican"
  $ stdres   : table [1:2, 1:3] 4.502 -4.502 0.699 -0.699 -5.316 ...
   ..- attr(*, "dimnames")=List of 2
   .. ..$ gender: chr [1:2] "M" "F"
   .. ..$ party : chr [1:3] "Democrat" "Independent" "Republican"
  - attr(*, "class")= chr "htest"

Now you can see that the values in the stdres object are really a list  
element and are in a table with particular row and column names. You  
get that object one of two ways. you ca use the "$" method as Dalgaard  
suggested or you can use "[[" with the name of the object:

Xsq[["stdres"]]
David Winsemius, MD
West Hartford, CT