public void TestSpecialFunctions_BetaRegularized() { // Maple: Ix := (x,a,b) -> int(t^(a-1)*(1-t)^(b-1),t=0..x)/Beta(a,b); // Compare with Maple: "evalf(Ix(x,0.2,0.2),20);", with relative accuracy Assert.That(Fn.BetaRegularized(0.2, 0.2, 0.0), NumericIs.AlmostEqualTo(0.0), "A1"); Assert.That(Fn.BetaRegularized(0.2, 0.2, 0.2), NumericIs.AlmostEqualTo(.39272216435257082965), "A2"); Assert.That(Fn.BetaRegularized(0.2, 0.2, 0.5), NumericIs.AlmostEqualTo(.50000000000000000000), "A3"); Assert.That(Fn.BetaRegularized(0.2, 0.2, 0.8), NumericIs.AlmostEqualTo(.60727783564742917036), "A4"); Assert.That(Fn.BetaRegularized(0.2, 0.2, 1.0), NumericIs.AlmostEqualTo(1.0000000000000000000), "A5"); // Compare with Maple: "evalf(Ix(x,0.6,1.2),20);", with relative accuracy Assert.That(Fn.BetaRegularized(0.6, 1.2, 0.0), NumericIs.AlmostEqualTo(0.0), "B1"); Assert.That(Fn.BetaRegularized(0.6, 1.2, 0.2), NumericIs.AlmostEqualTo(.42540331997033591754), "B2"); Assert.That(Fn.BetaRegularized(0.6, 1.2, 0.5), NumericIs.AlmostEqualTo(.71641011564425207256), "B3"); Assert.That(Fn.BetaRegularized(0.6, 1.2, 0.8), NumericIs.AlmostEqualTo(.91373194998181983314), "B4"); Assert.That(Fn.BetaRegularized(0.6, 1.2, 1.0), NumericIs.AlmostEqualTo(1.0000000000000000000), "B5"); // Compare with Maple: "evalf(Ix(x,7.0,1.2),20);", with relative accuracy Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.0), NumericIs.AlmostEqualTo(0.0), "C1"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.2), NumericIs.AlmostEqualTo(.20126888449347947608e-4), "C2"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.5), NumericIs.AlmostEqualTo(.11371092280417448678e-1), "C3"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.7), NumericIs.AlmostEqualTo(.11102090346884848038, 1e-14), "C4"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.8), NumericIs.AlmostEqualTo(.26774648551269072265, 1e-14), "C5"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.9), NumericIs.AlmostEqualTo(.56477467605979107895), "C6"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 0.95), NumericIs.AlmostEqualTo(.77753405618146275868), "C7"); Assert.That(Fn.BetaRegularized(7.0, 1.2, 1.0), NumericIs.AlmostEqualTo(1.0000000000000000000), "C8"); }
CumulativeDistribution(double x) { double xa = _alpha * x; double m = xa / (xa + _beta); return(Fn.BetaRegularized(0.5 * _alpha, 0.5 * _beta, m)); }
CumulativeDistribution(double x) { double beta = Fn.BetaRegularized( 0.5 * _degreesOfFreedom, 0.5, _degreesOfFreedom / (_degreesOfFreedom + (x * x))); return(0.5 + (0.5 * Math.Sign(x) * (_summand - beta))); }
SetDistributionParameters(int degreesOfFreedom) { if (!IsValidParameterSet(degreesOfFreedom)) { throw new ArgumentException(Properties.LocalStrings.ArgumentParameterSetInvalid, "degreesOfFreedom"); } _degreesOfFreedom = degreesOfFreedom; _chiSquareDistribution.SetDistributionParameters(degreesOfFreedom); double a = 0.5 * (_degreesOfFreedom + 1); double nLn = Fn.GammaLn(a); double dLn1 = Math.Log(Math.Sqrt(Math.PI * _degreesOfFreedom)); double dLn2 = Fn.GammaLn(0.5 * _degreesOfFreedom); _exponent = -a; _factor = Math.Exp(nLn - dLn1 - dLn2); _summand = Fn.BetaRegularized(0.5 * _degreesOfFreedom, 0.5, 1); }
CumulativeDistribution( double x ) { return(Fn.BetaRegularized(_alpha, _beta, x)); }
CumulativeDistribution(double x) { return(Fn.BetaRegularized(_n - x, x + 1, 1 - _p)); }