@Test void compareParentChildIntersection1() { int m = 1366; int m_t = 344; int n = 116; int n_t = 13; int m_pa_t = 5651; int n_pa_t = 60; double proportion = (double) m_t/m_pa_t; double result = hypergeometric.phypergeometric(m_pa_t, m_t, n_pa_t, n_t); double expected = 4.7583683370433105E-5; System.out.printf("%e", result); assertEquals(expected,result, EPSILON); }
public double phypergeometric(int n, double p, int k, int r) { if (k >= n) return 1.0; if (r < 1) { return 1.0; } double q = 1.0 - p; int np = (int) Math.round(n * p); int nq = (int) Math.round(n * q); double log_n_choose_k = lNchooseK(n, k); int top = k; if (np < k) { top = np; } double lfoo = lNchooseK(np, top) + lNchooseK(nq, k - top); double sum = 0.0; for (int i = top; i >= r; --i) { sum += Math.exp(lfoo - log_n_choose_k); if (i > r) { lfoo = lfoo + Math.log((double) i / (double) (np - i + 1)) + Math.log((double) (nq - k + i) / (double) (k - i + 1)); } } return sum; }
Hypergeometric { public double phypergeometric(int n, double p, int k, int r) { if (k >= n) return 1.0; if (r < 1) { return 1.0; } double q = 1.0 - p; int np = (int) Math.round(n * p); int nq = (int) Math.round(n * q); double log_n_choose_k = lNchooseK(n, k); int top = k; if (np < k) { top = np; } double lfoo = lNchooseK(np, top) + lNchooseK(nq, k - top); double sum = 0.0; for (int i = top; i >= r; --i) { sum += Math.exp(lfoo - log_n_choose_k); if (i > r) { lfoo = lfoo + Math.log((double) i / (double) (np - i + 1)) + Math.log((double) (nq - k + i) / (double) (k - i + 1)); } } return sum; } }
Hypergeometric { public double phypergeometric(int n, double p, int k, int r) { if (k >= n) return 1.0; if (r < 1) { return 1.0; } double q = 1.0 - p; int np = (int) Math.round(n * p); int nq = (int) Math.round(n * q); double log_n_choose_k = lNchooseK(n, k); int top = k; if (np < k) { top = np; } double lfoo = lNchooseK(np, top) + lNchooseK(nq, k - top); double sum = 0.0; for (int i = top; i >= r; --i) { sum += Math.exp(lfoo - log_n_choose_k); if (i > r) { lfoo = lfoo + Math.log((double) i / (double) (np - i + 1)) + Math.log((double) (nq - k + i) / (double) (k - i + 1)); } } return sum; } Hypergeometric(); }
Hypergeometric { public double phypergeometric(int n, double p, int k, int r) { if (k >= n) return 1.0; if (r < 1) { return 1.0; } double q = 1.0 - p; int np = (int) Math.round(n * p); int nq = (int) Math.round(n * q); double log_n_choose_k = lNchooseK(n, k); int top = k; if (np < k) { top = np; } double lfoo = lNchooseK(np, top) + lNchooseK(nq, k - top); double sum = 0.0; for (int i = top; i >= r; --i) { sum += Math.exp(lfoo - log_n_choose_k); if (i > r) { lfoo = lfoo + Math.log((double) i / (double) (np - i + 1)) + Math.log((double) (nq - k + i) / (double) (k - i + 1)); } } return sum; } Hypergeometric(); double phypergeometric(int n, double p, int k, int r); double phypergeometric(int m, int m_t, int n, int n_t); double dhyper(int x, int N, int M, int n); double phyper(int x, int N, int M, int n, boolean lowerTail); double lNchooseK(int n, int k); double logfact(int i); }
Hypergeometric { public double phypergeometric(int n, double p, int k, int r) { if (k >= n) return 1.0; if (r < 1) { return 1.0; } double q = 1.0 - p; int np = (int) Math.round(n * p); int nq = (int) Math.round(n * q); double log_n_choose_k = lNchooseK(n, k); int top = k; if (np < k) { top = np; } double lfoo = lNchooseK(np, top) + lNchooseK(nq, k - top); double sum = 0.0; for (int i = top; i >= r; --i) { sum += Math.exp(lfoo - log_n_choose_k); if (i > r) { lfoo = lfoo + Math.log((double) i / (double) (np - i + 1)) + Math.log((double) (nq - k + i) / (double) (k - i + 1)); } } return sum; } Hypergeometric(); double phypergeometric(int n, double p, int k, int r); double phypergeometric(int m, int m_t, int n, int n_t); double dhyper(int x, int N, int M, int n); double phyper(int x, int N, int M, int n, boolean lowerTail); double lNchooseK(int n, int k); double logfact(int i);  }