Skip to main content
fix
Source Link

A one(two-sided) Fisher's Exact test gives p-value = 0.092284.

function p = fexact(k, x, m, n)
%FEXACT Fisher's Exact test.
%   Y = FEXACT(K, X, M, N) calculates the P-value for Fisher's
%   Exact Test.
%   K, X, M and N must be nonnegative integer vectors of the same
%   length.  The following must also hold:
%   X <= N <= M, X <= K <= M and K + N - M <= X.  Here:
%   K is the number of items in the group,
%   X is the number of items in the group with the feature,
%   M is the total number of items,
%   N is the total number of items with the feature,

if nargin < 4
   help(mfilename);
   return;
end
nr = length(k);
if nr ~= length(x) | nr ~= length(m) | nr ~= length(n)
   help(mfilename);
   return;
end

na = nan;
v = na(ones(nr, 1));
mi = max(0, k + n - m);
ma = min(k, n);

d = hygepdf(x, m, k, n) * (1 + 5.8e-11);
for i = 1:nr
  y = hygepdf(mi(i):ma(i), m(i), k(i), n(i));
  v(i) = sum(y(y <= d(i)));
end
p = max(min(v, 1), 0);
p(isnan(v)) = nan;

For your example, try fexact(1e6, 3, 2e6, 13).

A one-sided Fisher's Exact test gives p-value = 0.092284.

function p = fexact(k, x, m, n)
%FEXACT Fisher's Exact test.
%   Y = FEXACT(K, X, M, N) calculates the P-value for Fisher's
%   Exact Test.
%   K, X, M and N must be nonnegative integer vectors of the same
%   length.  The following must also hold:
%   X <= N <= M, X <= K <= M and K + N - M <= X.  Here:
%   K is the number of items in the group,
%   X is the number of items in the group with the feature,
%   M is the total number of items,
%   N is the total number of items with the feature,

if nargin < 4
   help(mfilename);
   return;
end
nr = length(k);
if nr ~= length(x) | nr ~= length(m) | nr ~= length(n)
   help(mfilename);
   return;
end

na = nan;
v = na(ones(nr, 1));
mi = max(0, k + n - m);
ma = min(k, n);

d = hygepdf(x, m, k, n) * (1 + 5.8e-11);
for i = 1:nr
  y = hygepdf(mi(i):ma(i), m(i), k(i), n(i));
  v(i) = sum(y(y <= d(i)));
end
p = max(min(v, 1), 0);
p(isnan(v)) = nan;

For your example, try fexact(1e6, 3, 2e6, 13).

A (two-sided) Fisher's Exact test gives p-value = 0.092284.

function p = fexact(k, x, m, n)
%FEXACT Fisher's Exact test.
%   Y = FEXACT(K, X, M, N) calculates the P-value for Fisher's
%   Exact Test.
%   K, X, M and N must be nonnegative integer vectors of the same
%   length.  The following must also hold:
%   X <= N <= M, X <= K <= M and K + N - M <= X.  Here:
%   K is the number of items in the group,
%   X is the number of items in the group with the feature,
%   M is the total number of items,
%   N is the total number of items with the feature,

if nargin < 4
   help(mfilename);
   return;
end
nr = length(k);
if nr ~= length(x) | nr ~= length(m) | nr ~= length(n)
   help(mfilename);
   return;
end

na = nan;
v = na(ones(nr, 1));
mi = max(0, k + n - m);
ma = min(k, n);

d = hygepdf(x, m, k, n) * (1 + 5.8e-11);
for i = 1:nr
  y = hygepdf(mi(i):ma(i), m(i), k(i), n(i));
  v(i) = sum(y(y <= d(i)));
end
p = max(min(v, 1), 0);
p(isnan(v)) = nan;

For your example, try fexact(1e6, 3, 2e6, 13).

Source Link

A one-sided Fisher's Exact test gives p-value = 0.092284.

function p = fexact(k, x, m, n)
%FEXACT Fisher's Exact test.
%   Y = FEXACT(K, X, M, N) calculates the P-value for Fisher's
%   Exact Test.
%   K, X, M and N must be nonnegative integer vectors of the same
%   length.  The following must also hold:
%   X <= N <= M, X <= K <= M and K + N - M <= X.  Here:
%   K is the number of items in the group,
%   X is the number of items in the group with the feature,
%   M is the total number of items,
%   N is the total number of items with the feature,

if nargin < 4
   help(mfilename);
   return;
end
nr = length(k);
if nr ~= length(x) | nr ~= length(m) | nr ~= length(n)
   help(mfilename);
   return;
end

na = nan;
v = na(ones(nr, 1));
mi = max(0, k + n - m);
ma = min(k, n);

d = hygepdf(x, m, k, n) * (1 + 5.8e-11);
for i = 1:nr
  y = hygepdf(mi(i):ma(i), m(i), k(i), n(i));
  v(i) = sum(y(y <= d(i)));
end
p = max(min(v, 1), 0);
p(isnan(v)) = nan;

For your example, try fexact(1e6, 3, 2e6, 13).