internal double Probability(TestType type) { switch (type) { case TestType.LeftTailed: return(distribution.LeftProbability(value)); case TestType.RightTailed: return(distribution.RightProbability(value)); case TestType.TwoTailed: // This certainly works for symmetric distributions. // It also works for F-test, which is the one asymmetric case we care about // for the distributions we cover. Not clear that it is true in general, though. if (value < distribution.Median) { return(2.0 * distribution.LeftProbability(value)); } else { return(2.0 * distribution.RightProbability(value)); } default: throw new InvalidOperationException(); } }
private void DistributionProbabilityTestHelper(ContinuousDistribution distribution, double x) { Console.WriteLine("{0} {1}", distribution.GetType().Name, x); double P = distribution.LeftProbability(x); double Q = distribution.RightProbability(x); Assert.IsTrue((0.0 <= P) && (P <= 1.0)); Assert.IsTrue((0.0 <= Q) && (Q <= 1.0)); Assert.IsTrue(TestUtilities.IsNearlyEqual(P + Q, 1.0)); double p = distribution.ProbabilityDensity(x); Assert.IsTrue(p >= 0.0); }
private void DistributionProbabilityTestHelper(ContinuousDistribution distribution, double x) { double P = distribution.LeftProbability(x); double Q = distribution.RightProbability(x); Assert.IsTrue((0.0 <= P) && (P <= 1.0)); Assert.IsTrue((0.0 <= Q) && (Q <= 1.0)); Assert.IsTrue(TestUtilities.IsNearlyEqual(P + Q, 1.0)); double p = distribution.ProbabilityDensity(x); Assert.IsTrue(p >= 0.0); double h = distribution.Hazard(x); if (p > 0.0 && Q > 0.0) { Assert.IsTrue(TestUtilities.IsNearlyEqual(h, p / Q)); } }
private static void ComputeDStatistics(IReadOnlyList <double> sample, ContinuousDistribution distribution, out double D1, out double D2) { List <int> order = GetSortOrder(sample); D1 = 0.0; D2 = 0.0; double P1 = 0.0; for (int i = 0; i < sample.Count; i++) { // Compute the theoretical CDF value at the data-point. double x = sample[order[i]]; double P = distribution.LeftProbability(x); // compute the experimental CDF value at x+dx double P2 = (i + 1.0) / sample.Count; // Compare the the theoretical and experimental CDF values at x-dx and x+dx; // Update D if it is the largest seperation yet observed. double DU = P2 - P; if (DU > D1) { D1 = DU; } double DL = P - P1; if (DL > D2) { D2 = DL; } // Remember the experimental CDF value at x+dx; // it will be the experimental CDF value at x-dx for the next step P1 = P2; } }