Exemplo n.º 1
0
        public void ConstructorTest()
        {
            var F = new FDistribution(degrees1: 8, degrees2: 5);

            double mean   = F.Mean;                                     // 1.6666666666666667
            double median = F.Median;                                   // 1.0545096252132447
            double var    = F.Variance;                                 // 7.6388888888888893
            double mode   = F.Mode;                                     // 0.5357142857142857

            double cdf  = F.DistributionFunction(x: 0.27);              // 0.049463408057268315
            double pdf  = F.ProbabilityDensityFunction(x: 0.27);        // 0.45120469723580559
            double lpdf = F.LogProbabilityDensityFunction(x: 0.27);     // -0.79583416831212883

            double ccdf = F.ComplementaryDistributionFunction(x: 0.27); // 0.95053659194273166
            double icdf = F.InverseDistributionFunction(p: cdf);        // 0.27

            double hf  = F.HazardFunction(x: 0.27);                     // 0.47468419528555084
            double chf = F.CumulativeHazardFunction(x: 0.27);           // 0.050728620222091653

            string str = F.ToString(CultureInfo.InvariantCulture);      // F(x; df1 = 8, df2 = 5)

            Assert.AreEqual(0, F.Support.Min);
            Assert.AreEqual(double.PositiveInfinity, F.Support.Max);

            Assert.AreEqual(F.InverseDistributionFunction(0), F.Support.Min);
            Assert.AreEqual(F.InverseDistributionFunction(1), F.Support.Max);

            Assert.AreEqual(1.6666666666666667, mean);
            Assert.AreEqual(1.0545096252132447, median);
            Assert.AreEqual(7.6388888888888893, var);
            Assert.AreEqual(0.5357142857142857, mode);
            Assert.AreEqual(0.050728620222091653, chf);
            Assert.AreEqual(0.049463408057268315, cdf);
            Assert.AreEqual(0.45120469723580559, pdf);
            Assert.AreEqual(-0.79583416831212883, lpdf);
            Assert.AreEqual(0.47468419528555084, hf);
            Assert.AreEqual(0.95053659194273166, ccdf);
            Assert.AreEqual(0.27, icdf);
            Assert.AreEqual("F(x; df1 = 8, df2 = 5)", str);

            var range1 = F.GetRange(0.95);
            var range2 = F.GetRange(0.99);
            var range3 = F.GetRange(0.01);

            Assert.AreEqual(0.27118653875813753, range1.Min);
            Assert.AreEqual(4.8183195356568689, range1.Max);
            Assert.AreEqual(0.15078805233761733, range2.Min);
            Assert.AreEqual(10.289311046135927, range2.Max);
            Assert.AreEqual(0.1507880523376173, range3.Min);
            Assert.AreEqual(10.289311046135927, range3.Max);
        }
Exemplo n.º 2
0
        public void ConstructorTest()
        {
            var F = new FDistribution(degrees1: 8, degrees2: 5);

            double mean   = F.Mean;                                     // 1.6666666666666667
            double median = F.Median;                                   // 1.0545096252132447
            double var    = F.Variance;                                 // 7.6388888888888893

            double cdf  = F.DistributionFunction(x: 0.27);              // 0.049463408057268315
            double pdf  = F.ProbabilityDensityFunction(x: 0.27);        // 0.45120469723580559
            double lpdf = F.LogProbabilityDensityFunction(x: 0.27);     // -0.79583416831212883

            double ccdf = F.ComplementaryDistributionFunction(x: 0.27); // 0.95053659194273166
            double icdf = F.InverseDistributionFunction(p: cdf);        // 0.27

            double hf  = F.HazardFunction(x: 0.27);                     // 0.47468419528555084
            double chf = F.CumulativeHazardFunction(x: 0.27);           // 0.050728620222091653

            string str = F.ToString(CultureInfo.InvariantCulture);      // F(x; df1 = 8, df2 = 5)

            Assert.AreEqual(1.6666666666666667, mean);
            Assert.AreEqual(1.0545096252132447, median);
            Assert.AreEqual(7.6388888888888893, var);
            Assert.AreEqual(0.050728620222091653, chf);
            Assert.AreEqual(0.049463408057268315, cdf);
            Assert.AreEqual(0.45120469723580559, pdf);
            Assert.AreEqual(-0.79583416831212883, lpdf);
            Assert.AreEqual(0.47468419528555084, hf);
            Assert.AreEqual(0.95053659194273166, ccdf);
            Assert.AreEqual(0.27, icdf);
            Assert.AreEqual("F(x; df1 = 8, df2 = 5)", str);
        }
Exemplo n.º 3
0
        public static double Fisher(double significance_level, int fst_degree, int snd_degree)
        {
            var fd           = new FDistribution(fst_degree, snd_degree);
            var fisher_value = 1 / fd.InverseDistributionFunction(significance_level);

            return(fisher_value);
        }
Exemplo n.º 4
0
        public void InverseDistributionFunctionTest()
        {
            double[] cdf =
            {
                0.231238, 0.404508, 0.605516, 0.86038, 1.20711, 1.71825, 2.5611, 4.23607, 9.24342
            };

            FDistribution target = new FDistribution(4, 2);

            for (int i = 0; i < cdf.Length; i++)
            {
                double x        = (i + 1) / 10.0;
                double actual   = target.InverseDistributionFunction(x);
                double expected = cdf[i];

                Assert.AreEqual(expected, actual, 1e-5);
                Assert.IsFalse(double.IsNaN(actual));
            }
        }
Exemplo n.º 5
0
        public void MedianTest()
        {
            FDistribution target = new FDistribution(2, 3);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5));
        }