Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void ConstructorTest11()
        {
            var original = new ChiSquareDistribution(degreesOfFreedom: 7);

            var chisq = GeneralContinuousDistribution.FromDensityFunction(
                original.Support, original.ProbabilityDensityFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.DistributionFunction(i);
                double actual   = chisq.DistributionFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-5));
                Assert.IsFalse(Double.IsNaN(actual));
                Assert.IsFalse(Double.IsNaN(expected));
            }

            testChiSquare(chisq);
        }
Exemplo n.º 4
0
        public void DistributionFunctionTest()
        {
            int    degreesOfFreedom;
            double actual, expected, x;
            ChiSquareDistribution target;

            degreesOfFreedom = 1;
            target           = new ChiSquareDistribution(degreesOfFreedom);
            x        = 5;
            actual   = target.DistributionFunction(x);
            expected = 0.9747;
            Assert.AreEqual(expected, actual, 1e-4);


            degreesOfFreedom = 5;
            target           = new ChiSquareDistribution(degreesOfFreedom);
            x        = 5;
            actual   = target.DistributionFunction(x);
            expected = 0.5841;
            Assert.AreEqual(expected, actual, 1e-4);
        }