public void ProbabilityDensityFunctionTest() { double[] ranks = { 1, 2, 3, 4, 5 }; int n1 = 2; int n2 = 3; int N = n1 + n2; Assert.AreEqual(N, ranks.Length); var target = new MannWhitneyDistribution(ranks, n1, n2); // Number of possible combinations is 5!/(3!2!) = 10. int nc = (int)Special.Binomial(5, 3); Assert.AreEqual(10, nc); double[] expected = { 0.1, 0.1, 0.2, 0.2, 0.2, 0.1, 0.1, 0.0, 0.0 }; double sum = 0; for (int i = 0; i < expected.Length; i++) { // P(U=i) double actual = target.ProbabilityDensityFunction(i); Assert.AreEqual(expected[i], actual); sum += actual; } Assert.AreEqual(1, sum); }
public void ConstructorTest() { double[] ranks = { 1, 2, 3, 4, 5 }; var mannWhitney = new MannWhitneyDistribution(ranks, n1: 2, n2: 3); double mean = mannWhitney.Mean; // 2.7870954605658511 double median = mannWhitney.Median; // 1.5219615583481305 double var = mannWhitney.Variance; // 18.28163603621158 double cdf = mannWhitney.DistributionFunction(x: 4); // 0.6 double pdf = mannWhitney.ProbabilityDensityFunction(x: 4); // 0.2 double lpdf = mannWhitney.LogProbabilityDensityFunction(x: 4); // -1.6094379124341005 double ccdf = mannWhitney.ComplementaryDistributionFunction(x: 4); // 0.4 double icdf = mannWhitney.InverseDistributionFunction(p: cdf); // 3.6666666666666661 double hf = mannWhitney.HazardFunction(x: 4); // 0.5 double chf = mannWhitney.CumulativeHazardFunction(x: 4); // 0.916290731874155 string str = mannWhitney.ToString(); // MannWhitney(u; n1 = 2, n2 = 3) Assert.AreEqual(3.0, mean); Assert.AreEqual(3.0000006357828775, median); Assert.AreEqual(3.0, var); Assert.AreEqual(0.916290731874155, chf); Assert.AreEqual(0.6, cdf); Assert.AreEqual(0.2, pdf); Assert.AreEqual(-1.6094379124341005, lpdf); Assert.AreEqual(0.5, hf); Assert.AreEqual(0.4, ccdf); Assert.AreEqual(3.6666666666666661, icdf); Assert.AreEqual("MannWhitney(u; n1 = 2, n2 = 3)", str); }
public void ConstructorTest() { #region doc_create double[] ranks = { 1, 2, 3, 4, 5 }; var mannWhitney = new MannWhitneyDistribution(ranks, n1: 2, n2: 3); double mean = mannWhitney.Mean; // 2.7870954605658511 double median = mannWhitney.Median; // 1.5219615583481305 double var = mannWhitney.Variance; // 18.28163603621158 double mode = mannWhitney.Mode; double cdf = mannWhitney.DistributionFunction(x: 4); // 0.6 double pdf = mannWhitney.ProbabilityDensityFunction(x: 4); // 0.2 double lpdf = mannWhitney.LogProbabilityDensityFunction(x: 4); // -1.6094379124341005 double ccdf = mannWhitney.ComplementaryDistributionFunction(x: 4); // 0.4 double icdf = mannWhitney.InverseDistributionFunction(p: cdf); // 3.6666666666666661 double hf = mannWhitney.HazardFunction(x: 4); // 0.5 double chf = mannWhitney.CumulativeHazardFunction(x: 4); // 0.916290731874155 string str = mannWhitney.ToString(); // MannWhitney(u; n1 = 2, n2 = 3) #endregion Assert.AreEqual(3.0, mean); Assert.AreEqual(3.0, mode); Assert.AreEqual(3.0000006357828775, median, 1e-5); Assert.AreEqual(3.0, var, 1e-5); Assert.AreEqual(0.916290731874155, chf, 1e-8); Assert.AreEqual(0.8, cdf, 1e-8); Assert.AreEqual(0.2, pdf, 1e-8); Assert.AreEqual(-1.6094379124341005, lpdf, 1e-8); Assert.AreEqual(0.5, hf, 1e-8); Assert.AreEqual(0.4, ccdf, 1e-8); Assert.AreEqual(4, icdf, 1e-8); Assert.AreEqual("MannWhitney(u; n1 = 2, n2 = 3)", str); var range1 = mannWhitney.GetRange(0.95); var range2 = mannWhitney.GetRange(0.99); var range3 = mannWhitney.GetRange(0.01); Assert.AreEqual(0, range1.Min, 1e-5); Assert.AreEqual(6, range1.Max, 1e-5); Assert.AreEqual(-8.5830688476562492E-07, range2.Min, 1e-5); Assert.AreEqual(6.0000005561746477, range2.Max, 1e-4); Assert.AreEqual(-8.58306884765625E-07, range3.Min, 1e-5); Assert.AreEqual(6.0000005561746477, range3.Max, 1e-5); }
public void ConstructorTest() { double[] ranks = { 1, 2, 3, 4, 5 }; var mannWhitney = new MannWhitneyDistribution(ranks, n1: 2, n2: 3); double mean = mannWhitney.Mean; // 2.7870954605658511 double median = mannWhitney.Median; // 1.5219615583481305 double var = mannWhitney.Variance; // 18.28163603621158 try { double mode = mannWhitney.Mode; Assert.Fail(); } catch { } double cdf = mannWhitney.DistributionFunction(x: 4); // 0.6 double pdf = mannWhitney.ProbabilityDensityFunction(x: 4); // 0.2 double lpdf = mannWhitney.LogProbabilityDensityFunction(x: 4); // -1.6094379124341005 double ccdf = mannWhitney.ComplementaryDistributionFunction(x: 4); // 0.4 double icdf = mannWhitney.InverseDistributionFunction(p: cdf); // 3.6666666666666661 double hf = mannWhitney.HazardFunction(x: 4); // 0.5 double chf = mannWhitney.CumulativeHazardFunction(x: 4); // 0.916290731874155 string str = mannWhitney.ToString(); // MannWhitney(u; n1 = 2, n2 = 3) Assert.AreEqual(3.0, mean); Assert.AreEqual(3.0000006357828775, median); Assert.AreEqual(3.0, var); Assert.AreEqual(0.916290731874155, chf); Assert.AreEqual(0.6, cdf); Assert.AreEqual(0.2, pdf); Assert.AreEqual(-1.6094379124341005, lpdf); Assert.AreEqual(0.5, hf); Assert.AreEqual(0.4, ccdf); Assert.AreEqual(3.6666666666666661, icdf); Assert.AreEqual("MannWhitney(u; n1 = 2, n2 = 3)", str); var range1 = mannWhitney.GetRange(0.95); var range2 = mannWhitney.GetRange(0.99); var range3 = mannWhitney.GetRange(0.01); Assert.AreEqual(0.00000095367431640625085, range1.Min); Assert.AreEqual(5.9999995430310555, range1.Max); Assert.AreEqual(0, range2.Min); Assert.AreEqual(6.000000194140088, range2.Max); Assert.AreEqual(0, range3.Min); Assert.AreEqual(6.000000194140088, range3.Max); }