費雪正確性檢定 (Fisher's exact test)

套路34: 費雪正確性檢定 (Fisher's exact test)

1. 使用時機: 用於樣本數較少的列聯表的檢定檢定兩個隨機變數之間是否無關(independent)
2. 分析類型: 類別資料分析(Categorical Data Analysis)
3. 資料範例:
咪路調查不同性別大學生頭髮顏色資料如下:
髮色
黑色
紅色
總數
男生
5
2
7
女生
3
4
7
總數
8
6

試問髮色與性別是否有關?
H0: 髮色與性別無關(independent)
HA: 髮色與性別有關。

4. 使用Python計算費雪正確性檢定:
import scipy.stats
scipy.stats.fisher_exact([[5,2],[3,4]], alternative='two-sided')
結果: (3.3333333333333335, 0.5920745920745929)
# p = 0.592 > 0.05H0: 髮色與性別無關(independent)成立。
# 反之如果p-value < 0.05H0: 髮色與性別無關(independent)不成立。

5. 比較,相同數據以卡方獨立檢定分析因資料為2 x 2列聯表(degree of freedom = 1)時需做葉慈修正(Yates' correction)如下列範例所示:
import numpy as np
import scipy.stats
obs = np.array([[5,2], [3,4]])
scipy.stats.chi2_contingency(obs, correction = True)
結果:
(0.29166666666666663,     # The test statistic
0.5891544654500582,       # The p-value of the test
1,                        # Degrees of freedom = 1需做葉慈修正correction = True
array([[4., 3.],
        [4., 3.]]))
# p = 0.589 > 0.05H0: 髮色與性別無關(independent)成立。
# 反之如果p-value < 0.05H0: 髮色與性別無關(independent)不成立。


留言

這個網誌中的熱門文章

三因子變異數分析 (Three-Way ANOVA)

兩組獨立樣本變異數相同 t 檢定 (Two-Sample t test with equal variances,parametric)

雙因子變異數分析 (Two-Way ANOVA)