public void DifferentiationTest() { int i = 0; foreach (TestDerivative test in derivatives) { i++; foreach (double x in TestUtilities.GenerateRealValues(0.1, 100.0, 5)) { UncertainValue nd = FunctionMath.Differentiate(test.Function, x); double ed = test.Derivative(x); Console.WriteLine("{0} f'({1}) = {2} = {3}", i, x, nd, ed); Console.WriteLine( //Assert.IsTrue( nd.ConfidenceInterval(0.999).ClosedContains(ed) ); /* * TestUtilities.IsNearlyEqual( * FunctionMath.Differentiate(test.Function, x), * test.Derivative(x), * Math.Pow(2, -42) */ } } }
public void BinaryContingencyTest() { // Create a table with significant association and test for it. ContingencyTable e1 = CreateExperiment(0.50, 0.50, 0.75, 128); Assert.IsTrue(e1.RowTotal(0) + e1.RowTotal(1) == e1.Total); Assert.IsTrue(e1.ColumnTotal(0) + e1.ColumnTotal(1) == e1.Total); UncertainValue lnr = e1.Binary.LogOddsRatio; Assert.IsTrue(!lnr.ConfidenceInterval(0.95).ClosedContains(0.0)); UncertainValue r = e1.Binary.OddsRatio; Assert.IsTrue(!r.ConfidenceInterval(0.95).ClosedContains(1.0)); TestResult p = e1.PearsonChiSquaredTest(); Assert.IsTrue(p.Probability < 0.05); TestResult f = e1.Binary.FisherExactTest(); Assert.IsTrue(f.Probability < 0.05); }
public void BinaryContingencyNullTest() { // Create a table with no significant association and test for it. ContingencyTable e0 = CreateExperiment(0.25, 0.33, 0.33, 128); Assert.IsTrue(e0.Total == 128); Assert.IsTrue(e0.RowTotal(0) + e0.RowTotal(1) == e0.Total); Assert.IsTrue(e0.ColumnTotal(0) + e0.ColumnTotal(1) == e0.Total); UncertainValue lnr = e0.Binary.LogOddsRatio; Assert.IsTrue(lnr.ConfidenceInterval(0.95).ClosedContains(0.0)); UncertainValue r = e0.Binary.OddsRatio; Assert.IsTrue(r.ConfidenceInterval(0.95).ClosedContains(1.0)); TestResult p = e0.PearsonChiSquaredTest(); Assert.IsTrue(p.Probability > 0.05); TestResult f = e0.Binary.FisherExactTest(); Assert.IsTrue(f.Probability > 0.05); }
public void BinaryContingencyTest() { // Create a table with significant association and test for it. ContingencyTable e1 = CreateExperiment(0.50, 0.50, 0.75, 128); Assert.IsTrue(e1.RowTotal(0) + e1.RowTotal(1) == e1.Total); Assert.IsTrue(e1.ColumnTotal(0) + e1.ColumnTotal(1) == e1.Total); UncertainValue lnr = e1.Binary.LogOddsRatio; Assert.IsTrue(!lnr.ConfidenceInterval(0.95).ClosedContains(0.0)); UncertainValue r = e1.Binary.OddsRatio; Assert.IsTrue(!r.ConfidenceInterval(0.95).ClosedContains(1.0)); // Chi square should detect association TestResult p = e1.PearsonChiSquaredTest(); Assert.IsTrue(p.Probability < 0.05); // Fisher exact should detect association TestResult f = e1.Binary.FisherExactTest(); Assert.IsTrue(f.Probability < 0.05); // Phi should be the same as Pearson correlation coefficient List <double> x = new List <double>(); List <double> y = new List <double>(); for (int i = 0; i < e1[0, 0]; i++) { x.Add(0); y.Add(0); } for (int i = 0; i < e1[0, 1]; i++) { x.Add(0); y.Add(1); } for (int i = 0; i < e1[1, 0]; i++) { x.Add(1); y.Add(0); } for (int i = 0; i < e1[1, 1]; i++) { x.Add(1); y.Add(1); } double s = x.CorrelationCoefficient(y); Assert.IsTrue(TestUtilities.IsNearlyEqual(s, e1.Binary.Phi)); }
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); }