x
The Probability Density Function (PDF) describes the probability that a given value x will occur.
References: http://www.mathworks.com/access/helpdesk/help/toolbox/stats/chi2pdf.html
public void ConstructorTest() { var chisq = new ChiSquareDistribution(degreesOfFreedom: 7); double mean = chisq.Mean; // 7 double median = chisq.Median; // 6.345811195595612 double var = chisq.Variance; // 14 double cdf = chisq.DistributionFunction(x: 6.27); // 0.49139966433823956 double pdf = chisq.ProbabilityDensityFunction(x: 6.27); // 0.11388708001184455 double lpdf = chisq.LogProbabilityDensityFunction(x: 6.27); // -2.1725478476948092 double ccdf = chisq.ComplementaryDistributionFunction(x: 6.27); // 0.50860033566176044 double icdf = chisq.InverseDistributionFunction(p: cdf); // 6.2700000000852318 double hf = chisq.HazardFunction(x: 6.27); // 0.22392254197721179 double chf = chisq.CumulativeHazardFunction(x: 6.27); // 0.67609276602233315 string str = chisq.ToString(); // "χ²(x; df = 7) Assert.AreEqual(7, mean); Assert.AreEqual(6.345811195595612, median, 1e-6); Assert.AreEqual(14, var); Assert.AreEqual(0.67609276602233315, chf); Assert.AreEqual(0.49139966433823956, cdf); Assert.AreEqual(0.11388708001184455, pdf); Assert.AreEqual(-2.1725478476948092, lpdf); Assert.AreEqual(0.22392254197721179, hf); Assert.AreEqual(0.50860033566176044, ccdf); Assert.AreEqual(6.2700000000852318, icdf, 1e-6); Assert.AreEqual("χ²(x; df = 7)", str); }
public void ConstructorTest() { var chisq = new ChiSquareDistribution(degreesOfFreedom: 7); double mean = chisq.Mean; // 7 double median = chisq.Median; // 6.345811195595612 double var = chisq.Variance; // 14 double mode = chisq.Mode; // 5.0 double cdf = chisq.DistributionFunction(x: 6.27); // 0.49139966433823956 double pdf = chisq.ProbabilityDensityFunction(x: 6.27); // 0.11388708001184455 double lpdf = chisq.LogProbabilityDensityFunction(x: 6.27); // -2.1725478476948092 double ccdf = chisq.ComplementaryDistributionFunction(x: 6.27); // 0.50860033566176044 double icdf = chisq.InverseDistributionFunction(p: cdf); // 6.2700000000852318 double hf = chisq.HazardFunction(x: 6.27); // 0.22392254197721179 double chf = chisq.CumulativeHazardFunction(x: 6.27); // 0.67609276602233315 string str = chisq.ToString(); // "χ²(x; df = 7) Assert.AreEqual(7, mean); Assert.AreEqual(6.345811195595612, median, 1e-6); Assert.AreEqual(14, var); Assert.AreEqual(5.0, mode); Assert.AreEqual(0.67609276602233315, chf); Assert.AreEqual(0.49139966433823956, cdf); Assert.AreEqual(0.11388708001184455, pdf); Assert.AreEqual(-2.1725478476948092, lpdf); Assert.AreEqual(0.22392254197721179, hf); Assert.AreEqual(0.50860033566176044, ccdf); Assert.AreEqual(6.2700000000852318, icdf, 1e-6); Assert.AreEqual("χ²(x; df = 7)", str); var range1 = chisq.GetRange(0.95); var range2 = chisq.GetRange(0.99); var range3 = chisq.GetRange(0.01); Assert.AreEqual(2.1673499092980579, range1.Min); Assert.AreEqual(14.067140449340167, range1.Max); Assert.AreEqual(1.2390423055679316, range2.Min); Assert.AreEqual(18.475306906582361, range2.Max); Assert.AreEqual(1.2390423055679316, range3.Min); Assert.AreEqual(18.475306906582361, range3.Max); }
public void LogProbabilityDensityFunctionTest() { int degreesOfFreedom; double actual, expected, x; ChiSquareDistribution target; degreesOfFreedom = 1; target = new ChiSquareDistribution(degreesOfFreedom); x = 1; actual = target.LogProbabilityDensityFunction(x); expected = System.Math.Log(target.ProbabilityDensityFunction(x)); Assert.AreEqual(expected, actual, 1e-10); degreesOfFreedom = 2; target = new ChiSquareDistribution(degreesOfFreedom); x = 2; actual = target.LogProbabilityDensityFunction(x); expected = System.Math.Log(target.ProbabilityDensityFunction(x)); Assert.AreEqual(expected, actual, 1e-10); degreesOfFreedom = 10; target = new ChiSquareDistribution(degreesOfFreedom); x = 2; actual = target.LogProbabilityDensityFunction(x); expected = System.Math.Log(target.ProbabilityDensityFunction(x)); Assert.AreEqual(expected, actual, 1e-10); }
public void ProbabilityDensityFunctionTest() { int degreesOfFreedom; double actual, expected, x; ChiSquareDistribution target; degreesOfFreedom = 1; target = new ChiSquareDistribution(degreesOfFreedom); x = 1; actual = target.ProbabilityDensityFunction(x); expected = 0.2420; Assert.AreEqual(expected, actual, 1e-4); degreesOfFreedom = 2; target = new ChiSquareDistribution(degreesOfFreedom); x = 2; actual = target.ProbabilityDensityFunction(x); expected = 0.1839; Assert.AreEqual(expected, actual, 1e-4); degreesOfFreedom = 10; target = new ChiSquareDistribution(degreesOfFreedom); x = 2; actual = target.ProbabilityDensityFunction(x); expected = 0.0077; Assert.AreEqual(expected, actual, 1e-4); }
public void ConstructorTest10() { var original = new ChiSquareDistribution(degreesOfFreedom: 7); var chisq = GeneralContinuousDistribution.FromDistributionFunction( original.Support, original.DistributionFunction); for (double i = -10; i < +10; i += 0.1) { double expected = original.ProbabilityDensityFunction(i); double actual = chisq.ProbabilityDensityFunction(i); Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-7)); Assert.IsFalse(Double.IsNaN(actual)); Assert.IsFalse(Double.IsNaN(expected)); } testChiSquare(chisq); }