Skip to content

Question On CrossTable function in gmodels package

2 messages · eugen pircalabelu, Marc Schwartz

#
Hi R-users,
I have the following problem with CrossTable function within ?gmodels? package: the output of the function (format ?spss? and asresid=T) can not be stored within another object.
For example:
$t
         y
x          0  1  2
  0-5yrs   4  2  6
  6-11yrs 78 27 15
  12+ yrs 61 39 16
?????.
But when I call
NULL

Why is aaa object NULL? Should it be NULL? I suspect it has something to do with the SPSS-format option but I?m not sure 
The reason I want it stored in an object, is to use the adjusted standardized residuals in a LateX document with xtable. 
Does anyone have a solution, please?

Thank you very much and have a great day ahead!  


PS: 
sessionInfo()
R version 2.7.1 (2008-06-23) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gmodels_2.14.1 xtable_1.5-4  

loaded via a namespace (and not attached):
[1] gdata_2.3.1  gtools_2.4.0 MASS_7.2-42  tools_2.7.1
#
on 01/29/2009 08:01 AM eugen pircalabelu wrote:
In reviewing the code, it looks like the internal print function for the
SPSS formatted output does not include an invisible() returned object,
thus you get the NULL. This is a consequence of there being multiple
authors (me being one) who have contributed sections of code to the
function over the years. The function really needs to be re-designed
from scratch as it has become a monolith. I have not used it myself in
quite a few years.

If you only need a part of the results generated by the function, the
best approach would be to take that part of the code and use it separately:

TAB <- table(infert$education, infert$induced)
RS <- rowSums(TAB)
CS <- colSums(TAB)
GT <- sum(TAB)
CST <- chisq.test(TAB)

ASR <- (CST$observed - CST$expected) /
        sqrt(CST$expected * ((1 - RS / GT) %*% t(1 - CS / GT)))
0  1  2
  0-5yrs   4  2  6
  6-11yrs 78 27 15
  12+ yrs 61 39 16
0          1          2
  0-5yrs  -1.7484576 -0.8559305  3.4965329
  6-11yrs  2.2647496 -1.6814370 -1.0354298
  12+ yrs -1.5163521  2.0521732 -0.4666731


HTH,

Marc Schwartz