diff --git a/src/Numerics/Distributions/ChiSquared.cs b/src/Numerics/Distributions/ChiSquared.cs
index 4076a090..90249767 100644
--- a/src/Numerics/Distributions/ChiSquared.cs
+++ b/src/Numerics/Distributions/ChiSquared.cs
@@ -215,7 +215,7 @@ namespace MathNet.Numerics.Distributions
///
public double CumulativeDistribution(double x)
{
- return SpecialFunctions.GammaLowerIncomplete(_freedom/2.0, x/2.0)/SpecialFunctions.Gamma(_freedom/2.0);
+ return SpecialFunctions.GammaLowerRegularized(_freedom/2.0, x/2.0);
}
///
diff --git a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
index 1047c718..6bedc208 100644
--- a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
@@ -293,36 +293,30 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
///
/// Degrees of freedom.
/// Input X value.
- [TestCase(1.0, 0.0)]
- [TestCase(1.0, 0.1)]
- [TestCase(1.0, 1.0)]
- [TestCase(1.0, 5.5)]
- [TestCase(1.0, 110.1)]
- [TestCase(1.0, Double.PositiveInfinity)]
- [TestCase(2.0, 0.0)]
- [TestCase(2.0, 0.1)]
- [TestCase(2.0, 1.0)]
- [TestCase(2.0, 5.5)]
- [TestCase(2.0, 110.1)]
- [TestCase(2.0, Double.PositiveInfinity)]
- [TestCase(2.5, 0.0)]
- [TestCase(2.5, 0.1)]
- [TestCase(2.5, 1.0)]
- [TestCase(2.5, 5.5)]
- [TestCase(2.5, 110.1)]
- [TestCase(2.5, Double.PositiveInfinity)]
- [TestCase(Double.PositiveInfinity, 0.0)]
- [TestCase(Double.PositiveInfinity, 0.1)]
- [TestCase(Double.PositiveInfinity, 1.0)]
- [TestCase(Double.PositiveInfinity, 5.5)]
- [TestCase(Double.PositiveInfinity, 110.1)]
- [TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
- public void ValidateCumulativeDistribution(double dof, double x)
+ /// N[CDF[ChiSquare[dof], x],20]
+ [TestCase(1.0, 0.0, 0.0)]
+ [TestCase(1.0, 0.1, 0.24817036595415071751)]
+ [TestCase(1.0, 1.0, 0.68268949213708589717)]
+ [TestCase(1.0, 5.5, 0.98098352632769945624)]
+ [TestCase(1.0, 110.1, 1.0)]
+ [TestCase(2.0, 0.0, 0.0)]
+ [TestCase(2.0, 0.1, 0.048770575499285990909)]
+ [TestCase(2.0, 1.0, 0.39346934028736657640)]
+ [TestCase(2.0, 5.5, 0.93607213879329242730)]
+ [TestCase(2.0, 110.1, 1.0)]
+ [TestCase(2.5, 0.0, 0.0)]
+ [TestCase(2.5, 0.1, 0.020298266579604156571)]
+ [TestCase(2.5, 1.0, 0.28378995266531297417)]
+ [TestCase(2.5, 5.5, 0.90239512593899828629)]
+ [TestCase(2.5, 110.1, 1.0)]
+ [TestCase(10000.0, 1.0, 0.0)]
+ [TestCase(10000.0, 7500.0, 3.3640453687878842514e-84)]
+ [TestCase(20000.0, 1.0, 0.0)]
+ public void ValidateCumulativeDistribution(double dof, double x, double expected)
{
var n = new ChiSquared(dof);
- double expected = SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x / 2.0) / SpecialFunctions.Gamma(dof / 2.0);
- Assert.AreEqual(expected, n.CumulativeDistribution(x));
- Assert.AreEqual(expected, ChiSquared.CDF(dof, x));
+ Assert.That(n.CumulativeDistribution(x), Is.EqualTo(expected).Within(1e-14));
+ Assert.That(ChiSquared.CDF(dof, x), Is.EqualTo(expected).Within(1e-14));
}
}
}
diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj
index 102394a1..3b9505a2 100644
--- a/src/UnitTests/UnitTests.csproj
+++ b/src/UnitTests/UnitTests.csproj
@@ -343,6 +343,7 @@
+