[R] Pearson's Chi-squared Test
Mitsuo Igarashi
mitsu5 at ruby.famille.ne.jp
Sun Apr 13 05:23:53 CEST 2003
HI Jorge.
Jorge Magalh??s <jmagalhaes at oninetspeed.pt> wrote:
>
> 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)
I have read these sentences of the URL.
If you combine the data you cited of female and male, you get
the following table.
Active | 13 | 7 | 21 |
Placebo | 29 | 7 | 7 |
This is expressed as x<-matrix(c(13,7,21,29,7,7),2,3,byrow=TRUE).
> x
[,1] [,2] [,3]
[1,] 13 7 21
[2,] 29 7 7
> chisq.test(x) : This runs in R.
Pearson's Chi-squared test
data: x
X-squared = 13.055, df = 2, p-value = 0.001463
You can see the following sentennces in the URL you cited which
is the same calculation just as I write above.
STATISTICS FOR TABLE OF TREAT BY IMPROVE |
| |
| Statistic DF Value Prob |
| ------------------------------------------------------ |
| Chi-Square 2 13.055 0.001 |
Chi-squared value is completely same.
I like to add a note that this section you cited is "Tests of
Association for Two-Way Tables". And Cochran-Mantel-Haenszel
Chi-Squared Test is different from chisq.test in R.
You can find a very good basic lectures:"Data Analysis With Epi
Info" at http://www.sjsu.edu/faculty/gerstman/EpiInfo/ .
Good luck!
-------========--------
mitsu5
mitsu5 at ruby.famille.ne.jp
> 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.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list