我认为 MATLAB 中没有内置 Fisher 组合概率检验,但实现它应该不难:
P = [0.43 0.12 0.0021 0.05 0.017 0.001 0.025 0.038 0.35 0.29];
k = length(P);
首先,我们将创建一个辅助矩阵,根据需要对 P 中的元素求和:
% the following matrix is used to sun each n elements in a row:
n = 3;
summer = diag(ones(k,1));
for d = 1:n-1
summer = summer + diag(ones(k-d,1),-d);
end
如果我们跑P*summer
,我们得到:
ans =
Columns 1 through 6
0.5521 0.1721 0.0691 0.068 0.043 0.064
Columns 7 through 10
0.413 0.678 0.64 0.29
接下来,我们首先计算所有的 ln 来计算统计量P
然后将它们相加为 3(并乘以-2
):
% compute the combine fisher statistic:
X = -2.*log(P(:).')*summer;
结果:
X =
Columns 1 through 6
18.26 22.564 26.472 27.956 29.342 27.734
Columns 7 through 10
16.018 11.116 4.5754 2.4757
最后,我们根据卡方分布计算 p 值2*3 = 6
df:
% get the p-values for all combinations:
p_vals = chi2cdf(X(1:end-n+1),6,'upper');
我们得到:
p_vals =
Columns 1 through 6
0.005614 0.00095661 0.00018177 9.577e-05 5.2399e-05 0.00010546
Columns 7 through 8
0.013659 0.084865