public void BetaMeanTest2() { int trials = 161750; int successes = 10007; BetaDistribution betaDistribution = new BetaDistribution(successes, trials); double mean = betaDistribution.Mean; // 0.06187249616697166 double median = betaDistribution.Median; // 0.06187069085946604 double p025 = betaDistribution.InverseDistributionFunction(p: 0.025); // 0.06070354581334864 double p975 = betaDistribution.InverseDistributionFunction(p: 0.975); // 0.0630517079399996 string str = betaDistribution.ToString(); Assert.AreEqual(trials, betaDistribution.Trials); Assert.AreEqual(successes, betaDistribution.Successes); Assert.AreEqual(0.06187249616697166, mean); Assert.AreEqual(0.06187069085946604, median, 1e-6); Assert.AreEqual(0.06070354581334864, p025, 1e-6); Assert.AreEqual(0.0630517079399996, p975, 1e-6); Assert.AreEqual("B(x; α = 10008, β = 151744)", str); }
public void BetaMeanTest() { double alpha = 0.42; double beta = 1.57; BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); double mean = betaDistribution.Mean; // 0.21105527638190955 double median = betaDistribution.Median; // 0.11577706212908731 double var = betaDistribution.Variance; // 0.055689279830523512 double mode = betaDistribution.Mode; // 57.999999999999957 double chf = betaDistribution.CumulativeHazardFunction(x: 0.27); // 1.1828193992944409 double cdf = betaDistribution.DistributionFunction(x: 0.27); // 0.69358638272337991 double pdf = betaDistribution.ProbabilityDensityFunction(x: 0.27); // 0.94644031936694828 double lpdf = betaDistribution.LogProbabilityDensityFunction(x: 0.27); // -0.055047364344046057 double hf = betaDistribution.HazardFunction(x: 0.27); // 3.0887671630877072 double ccdf = betaDistribution.ComplementaryDistributionFunction(x: 0.27); // 0.30641361727662009 double icdf = betaDistribution.InverseDistributionFunction(p: cdf); // 0.26999999068687469 string str = betaDistribution.ToString(System.Globalization.CultureInfo.InvariantCulture); // "B(x; α = 0.42, β = 1.57) Assert.AreEqual(0.21105527638190955, mean); Assert.AreEqual(0.11577706212908731, median); Assert.AreEqual(57.999999999999957, mode); Assert.AreEqual(0.055689279830523512, var); Assert.AreEqual(1.1828193992944409, chf); Assert.AreEqual(0.69358638272337991, cdf); Assert.AreEqual(0.94644031936694828, pdf); Assert.AreEqual(-0.055047364344046057, lpdf); Assert.AreEqual(3.0887671630877072, hf); Assert.AreEqual(0.30641361727662009, ccdf); Assert.AreEqual(0.27, icdf, 1e-10); Assert.AreEqual("B(x; α = 0.42, β = 1.57)", str); Assert.IsFalse(Double.IsNaN(median)); var range1 = betaDistribution.GetRange(0.95); var range2 = betaDistribution.GetRange(0.99); var range3 = betaDistribution.GetRange(0.01); Assert.AreEqual(0.00045925525776717733, range1.Min); Assert.AreEqual(0.72381020663218609, range1.Max); Assert.AreEqual(0.0000099485893745082635, range2.Min); Assert.AreEqual(0.89625688707910811, range2.Max); Assert.AreEqual(0.0000099485893745082432, range3.Min); Assert.AreEqual(0.89625688707910811, range3.Max); }
public void BetaMeanTest() { double alpha = 0.42; double beta = 1.57; BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); double mean = betaDistribution.Mean; // 0.21105527638190955 double median = betaDistribution.Median; // 0.11577706212908731 double var = betaDistribution.Variance; // 0.055689279830523512 double chf = betaDistribution.CumulativeHazardFunction(x: 0.27); // 1.1828193992944409 double cdf = betaDistribution.DistributionFunction(x: 0.27); // 0.69358638272337991 double pdf = betaDistribution.ProbabilityDensityFunction(x: 0.27); // 0.94644031936694828 double lpdf = betaDistribution.LogProbabilityDensityFunction(x: 0.27); // -0.055047364344046057 double hf = betaDistribution.HazardFunction(x: 0.27); // 3.0887671630877072 double ccdf = betaDistribution.ComplementaryDistributionFunction(x: 0.27); // 0.30641361727662009 double icdf = betaDistribution.InverseDistributionFunction(p: cdf); // 0.26999999068687469 string str = betaDistribution.ToString(System.Globalization.CultureInfo.InvariantCulture); // "B(x; α = 0.42, β = 1.57) Assert.AreEqual(0.21105527638190955, mean); Assert.AreEqual(0.11577706212908731, median); Assert.AreEqual(0.055689279830523512, var); Assert.AreEqual(1.1828193992944409, chf); Assert.AreEqual(0.69358638272337991, cdf); Assert.AreEqual(0.94644031936694828, pdf); Assert.AreEqual(-0.055047364344046057, lpdf); Assert.AreEqual(3.0887671630877072, hf); Assert.AreEqual(0.30641361727662009, ccdf); Assert.AreEqual(0.27, icdf, 1e-10); Assert.AreEqual("B(x; α = 0.42, β = 1.57)", str); }