s-news
[Top] [All Lists]

expected counts in crosstabs

To: s-news@lists.biostat.wustl.edu
Subject: expected counts in crosstabs
From: Russell.Ivory@merrickbank.com
Date: Fri, 11 Jun 2004 12:31:45 -0600

Hi group.

Does anyone know how to get expected counts in each cell of the crosstabs function ?  I can generate the expected counts as a separate matrix and would like to 'add an attribute'  labeled "Expected" to the crosstab object.  For example, the object 'mytest' looks like this

> mytest
Call:
crosstabs(formula =  ~ EFX002m + responded, data = "" subset = which(EFX002m == 1 | EFX002m == 90))
3524 cases in table
+----------+
|N         |
|N/RowTotal|
|N/ColTotal|
|N/Total   |
+----------+
EFX002m|responded
       |0      |1      |RowTotl|
-------+-------+-------+-------+
1      |1344   |1423   |2767   |
       |0.49   |0.51   |0.79   |
       |0.76   |0.82   |       |
       |0.38   |0.4    |       |
-------+-------+-------+-------+
90     | 435   | 322   |757    |
       |0.57   |0.43   |0.21   |
       |0.24   |0.18   |       |
       |0.12   |0.091  |       |
-------+-------+-------+-------+
ColTotl|1779   |1745   |3524   |
       |0.5    |0.5    |       |
-------+-------+-------+-------+
Test for independence of all factors
        Chi^2 = 18.79712 d.f.= 1 (p=0.00001453862)
        Yates' correction not used



And the matrix of expected values I generate looks like this

> exptbl
          0        1
 1 1396.8482 1370.9370
90  382.1518  374.8482


And I'd like the final output to look something like this

+----------+
|N         |
|N/RowTotal|
|N/ColTotal|
|N/Total   |
|Expected  |
+----------+
EFX002m|responded
       |0      |1      |RowTotl|
-------+-------+-------+-------+
1      |1344   |1423   |2767   |
       |0.49   |0.51   |0.79   |
       |0.76   |0.82   |       |
       |0.38   |0.4    |       |
                |1396.8 |1370.9 |       |
-------+-------+-------+-------+
90     | 435   | 322   |757    |
       |0.57   |0.43   |0.21   |
       |0.24   |0.18   |       |
       |0.12   |0.091  |       |
                |382.2  |374.8  |       |
-------+-------+-------+-------+
ColTotl|1779   |1745   |3524   |
       |0.5    |0.5    |       |
-------+-------+-------+-------+

I've tried fiddling with the attributes function but with no luck.  I'm not sure how to deal with the crosstabs class object.  Any thoughts are greatly appreciated.


Russell Ivory
AVP Modeling Manager
Merrick Bank
Salt Lake City, UT 84109
(801) 545-6640


                                                                                                          ****************************************************************************This e-mail and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom it is addressed.  If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, be advised that you have received this e-mail in error, and that any use, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited.  If you received this e-mail in error, please return the e-mail to the sender at Merrick Bank and delete it from your computer.  Although Merrick Bank attempts to sweep e-mail and attachments for viruses, it does not guarantee that either are virus-free and accepts no liability for any damage sustained as a result of viruses.

<Prev in Thread] Current Thread [Next in Thread>
  • expected counts in crosstabs, Russell . Ivory <=