Ejemplo n.º 1
0
        public void ConstructorTest()
        {
            var t = new TDistribution(degreesOfFreedom: 4.2);

            double mean = t.Mean;     // 0.0
            double median = t.Median; // 0.0
            double var = t.Variance;  // 1.9090909090909089

            double cdf = t.DistributionFunction(x: 1.4); // 0.88456136730659074
            double pdf = t.ProbabilityDensityFunction(x: 1.4); // 0.13894002185341031
            double lpdf = t.LogProbabilityDensityFunction(x: 1.4); // -1.9737129364307417

            double ccdf = t.ComplementaryDistributionFunction(x: 1.4); // 0.11543863269340926
            double icdf = t.InverseDistributionFunction(p: cdf); // 1.4000000000000012

            double hf = t.HazardFunction(x: 1.4); // 1.2035833984833988
            double chf = t.CumulativeHazardFunction(x: 1.4); // 2.1590162088918525

            string str = t.ToString(CultureInfo.InvariantCulture); // T(x; df = 4.2)

            Assert.AreEqual(0.0, mean);
            Assert.AreEqual(0.0, median);
            Assert.AreEqual(1.9090909090909089, var);
            Assert.AreEqual(2.1590162088918525, chf);
            Assert.AreEqual(0.88456136730659074, cdf);
            Assert.AreEqual(0.13894002185341031, pdf);
            Assert.AreEqual(-1.9737129364307417, lpdf);
            Assert.AreEqual(1.2035833984833988, hf);
            Assert.AreEqual(0.11543863269340926, ccdf);
            Assert.AreEqual(1.4000000000000012, icdf);
            Assert.AreEqual("T(x; df = 4.2)", str);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the cumulative distribution function (cdf) for
        /// this distribution evaluated at point <c>x</c>.
        /// </summary>
        /// <param name="x">A single point in the distribution range.</param>
        /// <returns>System.Double.</returns>
        /// <remarks>The Cumulative Distribution Function (CDF) describes the cumulative
        /// probability that a given value or any value smaller than it will occur.</remarks>
        protected internal override double InnerDistributionFunction(double x)
        {
            // http://graphpad.com/support/faqid/1598/
            double N   = NumberOfSamples;
            double num = N * (N - 2) * x * x;
            double den = ((N - 1) * (N - 1)) - N * x * x;
            double t   = Math.Sqrt(num / den);
            double p   = tDistribution.ComplementaryDistributionFunction(t);
            double r   = 1.0 - N * p;

            if (r > 1)
            {
                return(1);
            }
            if (r < 0)
            {
                return(0);
            }
            return(r);
        }