[R] Pearson's Chi-squared Test

Jorge Magalhães jmagalhaes at oninetspeed.pt
Sat Apr 12 01:19:52 CEST 2003


How i can perform a Pearson's Chi-squared Test  in this data set:

                                  |          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

if i do:
y<- matrix(c(5,6,16, 19,7,6,7,2,5,10,0,1), nc=3)

and 

chisq.test(y) i found that X-squared=20.3176 but the true value is 15.075 
(http://www.math.yorku.ca/SCS/Courses/grcat/grc2.html#H2_43:Sample) 

Now i tried:

the Cochran-Mantel-Haenszel Chi-Squared Test for Count Data:

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

mantelhaen.test(x)

and now X-squared=2.0863

What is wrong?

Best regards
Many thanks in advance

Jorge M.



More information about the R-help mailing list