public void ConstructorTest4() { // Create a new Shapiro-Wilk's W for 5 samples var sw = new ShapiroWilkDistribution(samples: 5); double mean = sw.Mean; // 0.8490362043845332 double median = sw.Median; // 0.8490362043845332 double mode = sw.Mode; // 0.8490362043845332 double cdf = sw.DistributionFunction(x: 0.84); // 0.16492187919271617 double pdf = sw.ProbabilityDensityFunction(x: 0.84); // 0.82021062372326459 double lpdf = sw.LogProbabilityDensityFunction(x: 0.84); // -0.1981941135071546 double ccdf = sw.ComplementaryDistributionFunction(x: 0.84); // 0.83507812080728383 double icdf = sw.InverseDistributionFunction(p: cdf); // 0.84000000194587177 double hf = sw.HazardFunction(x: 0.84); // 0.98219627994845971 double chf = sw.CumulativeHazardFunction(x: 0.84); // 0.18023000065451003 string str = sw.ToString(CultureInfo.InvariantCulture); // W(x; n = 12) Assert.AreEqual(0.8490362043845332, mean); Assert.AreEqual(0.8490362043845332, mode); Assert.AreEqual(0.8490362043845332, median, 1e-8); Assert.AreEqual(0.18023000065451003, chf); Assert.AreEqual(0.16492187919271617, cdf); Assert.AreEqual(0.82021062372326459, pdf); Assert.AreEqual(-0.1981941135071546, lpdf); Assert.AreEqual(0.98219627994845971, hf); Assert.AreEqual(0.83507812080728383, ccdf); Assert.AreEqual(0.84000000194587177, icdf, 1e-8); Assert.AreEqual("W(x; n = 5)", str); var range1 = sw.GetRange(0.95); Assert.AreEqual(0.77509977845943778, range1.Min, 1e-6); Assert.AreEqual(0.98299906816568339, range1.Max, 1e-6); var range2 = sw.GetRange(0.99); Assert.AreEqual(0.70180031139628618, range2.Min, 1e-6); Assert.AreEqual(0.99334588234528642, range2.Max, 1e-6); var range3 = sw.GetRange(0.01); Assert.AreEqual(0.70180031139628618, range3.Min, 1e-6); Assert.AreEqual(0.99334588234528642, range3.Max, 1e-6); Assert.AreEqual(0, sw.Support.Min); Assert.AreEqual(1, sw.Support.Max); Assert.AreEqual(sw.InverseDistributionFunction(0), sw.Support.Min); Assert.AreEqual(sw.InverseDistributionFunction(1), sw.Support.Max); }
public void ConstructorTest3() { var sw = new ShapiroWilkDistribution(samples: 12); double mean = sw.Mean; // 0.940148636841248 double median = sw.Median; // 0.940148636841248 double mode = sw.Mode; // 0.940148636841248 double cdf = sw.DistributionFunction(x: 0.42); // 4.8168255270011394E-06 double pdf = sw.ProbabilityDensityFunction(x: 0.42); // 0.000043477460596194137 double lpdf = sw.LogProbabilityDensityFunction(x: 0.42); // -10.043267901368219 double ccdf = sw.ComplementaryDistributionFunction(x: 0.42); // 0.999995183174473 double icdf = sw.InverseDistributionFunction(p: cdf); // 0.42000002275671627 double hf = sw.HazardFunction(x: 0.42); // 4.3477670020544943E-05 double chf = sw.CumulativeHazardFunction(x: 0.42); // 4.8168371279400235E-06 string str = sw.ToString(CultureInfo.InvariantCulture); // W(x; n = 12) Assert.AreEqual(0.940148636841248, mean); Assert.AreEqual(0.940148636841248, mode); Assert.AreEqual(0.940148636841248, median, 1e-8); Assert.AreEqual(4.8168371279400235E-06, chf); Assert.AreEqual(4.8168255270011394E-06, cdf); Assert.AreEqual(0.000043477460596194137, pdf); Assert.AreEqual(-10.043267901368219, lpdf); Assert.AreEqual(4.3477670020544943E-05, hf); Assert.AreEqual(0.999995183174473, ccdf); Assert.AreEqual(0.42000002275671627, icdf, 1e-8); Assert.AreEqual("W(x; n = 12)", str); var range1 = sw.GetRange(0.95); Assert.AreEqual(0.8607805197002204, range1.Min, 1e-6); Assert.AreEqual(0.97426955790462533, range1.Max, 1e-6); var range2 = sw.GetRange(0.99); Assert.AreEqual(0.80248479750351542, range2.Min, 1e-6); Assert.AreEqual(0.98186388183806661, range2.Max, 1e-6); var range3 = sw.GetRange(0.01); Assert.AreEqual(0.80248479750351542, range3.Min, 1e-6); Assert.AreEqual(0.98186388183806661, range3.Max, 1e-6); Assert.AreEqual(0, sw.Support.Min); Assert.AreEqual(1, sw.Support.Max); Assert.AreEqual(sw.InverseDistributionFunction(0), sw.Support.Min); Assert.AreEqual(sw.InverseDistributionFunction(1), sw.Support.Max); }