卡方独立性检验chiq.test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# method 1
> x=c(454,1833,2120)
> y=c(52,216,240)
> df=as.table(rbind(x,y))
# df=as.table(rbind(c(454,1833,2120),c(52,216,240)))
> df
A B C
A 454 1833 2120
B 52 216 240
> chisq.test(df)
Pearson's Chi-squared test
data: df
X-squared = 0.1661, df = 2, p-value = 0.9203
# method 2
> df2=matrix(c(454,1833,2120,52,216,240),nr=3)
> df2
[,1] [,2]
[1,] 454 52
[2,] 1833 216
[3,] 2120 240
> chisq.test(df2)
Pearson's Chi-squared test
data: df2
X-squared = 0.1661, df = 2, p-value = 0.9203