醫學統計學 第七章 卡方檢驗


第一節 四格表資料的卡方分布

例7-1 兩組降低顱內壓有效率的比較

  組別    有效    無效    合計    有效率
試驗組    99      5       104      95.2%
對照組    75      21      96        78.13
合計      174     26       200      87

卡方檢驗的步驟
H0 :pi1=pi2
H1 :Pi1 不等於 Pi2

> x<-c(99,75,5,21)
> dim(x)<-c(2,2)
> x
     [,1] [,2]
[1,]   99    5
[2,]   75   21
> chisq.test(x)

	Pearson's Chi-squared test with Yates' continuity correction

data:  x
X-squared = 11.392, df = 1, p-value = 0.0007375

P值<0.005 按a=0.05的水准,拒絕H0,接收H1,認為兩組有效率不相等

對於四格表資料 通常規定:(n總樣本數,T理論頻數)

  1. 當n>40且所有的T>5時,用卡方檢驗的基本公式(套用chisp.test()),當p-value 接近檢驗水准a時。改用四格表資料的fisher確切概率法(fisher.test());
  2. 當n>40,但有1<T<5時,用四格表資料的fisher確切概率法
  3. 當n<40,或T<1時,用用四格表資料的fisher確切概率法

例7-2 兩種葯物治療腦血管疾病有效率的比較

 組別    有效    無效    合計    有效率
胞鹼組    46      6       52      88.46%
苷鹼組    18      8(4.67) 36    69.23%
合計      64     14        78      82.05

其中 T(2,2)=(36*14)/78=4.67
運用fisher.test


> x<-c(46,18,6,8)
> dim(x)<-c(2,2)
> x
     [,1] [,2]
[1,]   46    6
[2,]   18    8
> fisher.test(x)

	Fisher's Exact Test for Count Data

data:  x
p-value = 0.05844
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
  0.879042 13.548216
sample estimates:
odds ratio 
  3.347519 

P值>0.05,不拒絕H0,還不能認為兩種葯品的有效率不等

第二節 配對四格表資料的卡方檢驗

例7-3 計數資料的配對設計常用於兩種檢驗方法、培養方法、診斷方法的比較。

                  乳膠凝集法
免疫熒光法    陽性        陰性         合計
陽性            11        12            23
陰性            2         33             35
合計            13        45            58

運用Mcnemar test

> x<-c(11,2,12,33)
> dim(x)<-c(2,2)
> x
     [,1] [,2]
[1,]   11   12
[2,]    2   33
> mcnemar.test(x)

	McNemar's Chi-squared test with continuity correction

data:  x
McNemar's chi-squared = 5.7857, df = 1, p-value = 0.01616

第三節 四格表資料的fisher確切概率法

例7-4 當四格表資料中的n<40或T<1時,或者chisq.test 所得結果不准確時,運用fisher.test ,其理論依據是超幾何分布(hypergeometric distribution)

        兩組新生兒HBV感染率的比較
組別    陽性    陰性    合計    感染率
預防組    4       18    22        18.18%
非預防    5(3)  6      11        45.45
合計      9       24     33        27.27
樣本總數33 小於40,

解法如下

> x<-c(4,5,18,6)
> dim(x)<-c(2,2)
> x
     [,1] [,2]
[1,]    4   18
[2,]    5    6
> chisq.test(x)

	Pearson's Chi-squared test with Yates' continuity correction

data:  x
X-squared = 1.5469, df = 1, p-value = 0.2136

Warning message:
In chisq.test(x) : Chi-squared近似算法有可能不准  # 在R語言中很明顯的提示
> fisher.test(x)

	Fisher's Exact Test for Count Data

data:  x
p-value = 0.121
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.03974151 1.76726409
sample estimates:
odds ratio 
 0.2791061 

例 7-5

        膽囊腺癌和膽囊腺瘤P53基因表達陽性率的比較
病種             陽性        陰性        合計
腺癌            6(3.5)      4            10
腺瘤            1(3.5)      9            10
合計            7            13            20
n<40 ,且 有兩個格子的理論頻數3.5<5 ,應用fisher確切概率法
> x<-c(6,1,4,9)
> dim(x)<-c(2,2)
> x
     [,1] [,2]
[1,]    6    4
[2,]    1    9
> fisher.test(x)

	Fisher's Exact Test for Count Data

data:  x
p-value = 0.05728
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
   0.9487882 684.4235629
sample estimates:
odds ratio 
   11.6367 

> #7-6 多個樣本率的比較
> x<-c(199,164,118,7,18,26)
> dim(x)<-c(3,2)
> x
     [,1] [,2]
[1,]  199    7
[2,]  164   18
[3,]  118   26
> chisq.test(x)

	Pearson's Chi-squared test

data:  x
X-squared = 21.038, df = 2, p-value = 2.702e-05

 #7-7 樣本構成比 比較
> x<-c(42,30,48,72,21,36)
> dim(x)<-c(2,3)
> x
     [,1] [,2] [,3]
[1,]   42   48   21
[2,]   30   72   36
> chisq.test(x)

	Pearson's Chi-squared test

data:  x
X-squared = 7.9127, df = 2, p-value = 0.01913

> #7-8雙向無序分類資料的關聯性檢驗
> x<-c(431,388,495,137,490,410,587,179,902,800,950,32)
> dim(x)<-c(4,3)
> chisq.test(x)

	Pearson's Chi-squared test

data:  x
X-squared = 213.16, df = 6, p-value < 2.2e-16

> chisq.test(x)$statistic
X-squared 
 213.1616 
> a<-chisq.test(x)$statistic
> #列聯系數
> C=sqrt(a/(5801+a));C
X-squared 
0.1882638 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM