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()); }
private static BinaryContingencyTable CreateExperiment(double p, double q0, double q1, int N) { BinaryContingencyTable e = new BinaryContingencyTable(); Random rng = new Random(1); for (int i = 0; i < N; i++) { int r, c; if (rng.NextDouble() < p) { r = 0; if (rng.NextDouble() < q0) { c = 0; } else { c = 1; } } else { r = 1; if (rng.NextDouble() < q1) { c = 0; } else { c = 1; } } e[r, c] += 1; } return(e); }
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); }
public void BinaryContingencyInvalidConstructionTest() { int[,] M = new int[2, 3]; BinaryContingencyTable t = new BinaryContingencyTable(M); }
public void BCT() { BinaryContingencyTable B = new BinaryContingencyTable(); }