// Calculate P-value based on Fisher's exact test.
double fpval(double nm, double nn, double bm, double bn)
{
	double contingency_table[4] = {nm, nn, bm, bn};

	// stuff for Fisher's test.
	int nrow = 2;
	int *nrowp = &nrow;
	int ncol = 2;
	int *ncolp = &ncol;
	double expected = -1.0;
	double percnt = 100.0;
	double emin = 0.0;
	double prt = 0.0;
	double *expectedp = &expected;
	double *percntp = %
	double *eminp = &emin;
	double *prtp = &prt;
	double pvalue = 0.0;
	double *pvaluep = &pvalue;
	int workspace = 300000;
	int *workspacep = &workspace;
	fexact(nrowp, ncolp, contingency_table, nrowp, expectedp, percntp, eminp, prtp, pvaluep, workspacep);

	return pvalue;
}
예제 #2
0
파일: gw_maths.cpp 프로젝트: gaow/RarePower
double fexact_two_sided_pvalue(const std::vector<int> &twotwoTable) 
{
  // This is specific for 2x2 tables. contingency_table = matrix(twotwoTable, 2, 2, byrow = T)

  double contingency_table[4] = {0, 0, 0, 0};
  for (int i = 0; i != 4; ++i) contingency_table[i] = twotwoTable[i];
  //stuff for Fisher's test
  int nrow = 2;
  int ncol = 2;
  double expected = -1.0;
  double percnt = 100.0;
  double emin = 0.0;
  double prt = 0.0;
  double pvalue = 0.0;
  int workspace = 300000;

  fexact(&nrow, &ncol, contingency_table, &nrow, &expected, &percnt, &emin, &prt, &pvalue, &workspace);
  return pvalue;
}