Skip to content
Prev 30491 / 398506 Next

Pearson's Chi-squared Test

Jorge Magalh?es <jmagalhaes at oninetspeed.pt> writes:
[that was garbled. Here's the original]

                      |         Outcome
   ---------+---------+--------------------------+
   Treatment|  Sex    |None    |Some    |Marked  |  Total
   ---------+---------+--------+--------+--------+
   Active   |  Female |      6 |      5 |     16 |     27
            |  Male   |      7 |      2 |      5 |     14
   ---------+---------+--------+--------+--------+
   Placebo  |  Female |     19 |      7 |      6 |     32
            |  Male   |     10 |      0 |      1 |     11
   ---------+---------+--------+--------+--------+
   Total                    42       14       28       84
No you don't, and I don't see the value 15.075 anywhere on that page.

Please check your input, rather than relying on r-helpers to do so:
y<- matrix(c(6,5,16, 19,7,6,7,2,5,10,0,1), nc=3,byrow=T)
             !!!                                !!!!!!!

will give you the 20.3176, but that test (for independence in the 4x3
table) isn't on the page you cite.
 
With correct entry of your "x" table (see below) you might have
calculated the 2x3 marginal over sex and gotten
Pearson's Chi-squared test

data:  margin.table(x, c(1, 3))
X-squared = 13.055, df = 2, p-value = 0.001463

which is indeed in the SAS output.
Printing that table ought to have given you a clue. Here's the right
way:

 x <- array(c(6, 19, 7, 10,
              5,  7, 2, 0,
             16,  6, 5, 1),
        dim = c(2, 2, 3),
        dimnames = list(
           treat=c("Active","Placebo"),
           sex=c("Female", "Male"),
           Outcome.Level = c("None", "Some", "Marked")))

However, for the Mantel-Haenszel test you'd want to stratify by sex,
not outcome, as happens when that is the last dimension of the table,
so use aperm to sort the indices differently:

mantelhaen.test(aperm(x,c(3,1,2))

gives 14.6323, as in SAS.