public void BinaryContingencyNullTest() { BinaryContingencyTable e0 = CreateExperiment(0.25, 0.33, 0.33, 200); Assert.IsTrue(e0.Total == 200); Assert.IsTrue(e0.RowTotal(0) + e0.RowTotal(1) == e0.Total); Assert.IsTrue(e0.ColumnTotal(0) + e0.ColumnTotal(1) == e0.Total); UncertainValue lnr = e0.LogOddsRatio; Assert.IsTrue(lnr.ConfidenceInterval(0.95).ClosedContains(0.0)); UncertainValue r = e0.OddsRatio; Assert.IsTrue(r.ConfidenceInterval(0.95).ClosedContains(1.0)); TestResult f = e0.FisherExactTest(); Assert.IsTrue(f.RightProbability < 0.95, f.RightProbability.ToString()); }
public void BinaryContingencyTest() { BinaryContingencyTable e1 = CreateExperiment(0.50, 0.50, 0.75, 200); Assert.IsTrue(e1.RowTotal(0) + e1.RowTotal(1) == e1.Total); Assert.IsTrue(e1.ColumnTotal(0) + e1.ColumnTotal(1) == e1.Total); UncertainValue lnr = e1.LogOddsRatio; Assert.IsFalse(lnr.ConfidenceInterval(0.95).ClosedContains(0.0)); UncertainValue r = e1.OddsRatio; Assert.IsFalse(r.ConfidenceInterval(0.95).ClosedContains(1.0)); TestResult p = e1.PearsonChiSquaredTest(); Assert.IsTrue(p.LeftProbability > 0.95, p.RightProbability.ToString()); TestResult f = e1.FisherExactTest(); Assert.IsTrue(f.RightProbability > 0.95); }
private Dictionary <string, double> FisherExactTest(Dictionary <string, int> background, Dictionary <string, int> test) { Dictionary <string, double> pvalueDict = new Dictionary <string, double>(); int totalBackground = background.Values.Sum(); int totalTest = test.Values.Sum(); foreach (KeyValuePair <string, int> kvp in test) { int backgroundCount = background[kvp.Key]; int testCount = kvp.Value; BinaryContingencyTable table = new BinaryContingencyTable(); //I got this from Doug's code. I hope it is right. int upperleft = testCount; int upperright = backgroundCount - upperleft; int lowerleft = totalTest - upperleft; int lowerright = totalBackground - totalTest - upperright; table[0, 0] = upperleft; table[0, 1] = upperright; table[1, 0] = lowerleft; table[1, 1] = lowerright; TestResult fisherExactResult = table.FisherExactTest(); double pvalueLeft = fisherExactResult.LeftProbability; double pvalueRight = fisherExactResult.LeftProbability; pvalueDict.Add(kvp.Key, pvalueRight); } Dictionary <string, double> qvalueDict = BenjaminiHochberg(pvalueDict); return(qvalueDict); }