DistributionFunction() public method

Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
The Cumulative Distribution Function (CDF) describes the cumulative probability that a given value or any value smaller than it will occur.
public DistributionFunction ( double x ) : double
x double A single point in the distribution range.
return double
Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Tests the null hypothesis that the population mean is equal to a specified value.
        /// </summary>
        /// 
        public TTest(double[] sample, double hypothesizedMean, TTestHypotesis type)
        {
            int n = sample.Length;
            double x = Accord.Statistics.Tools.Mean(sample);
            double s = Accord.Statistics.Tools.StandardDeviation(sample, x);

            StatisticDistribution = new TDistribution(n - 1);
            Statistic = (x - hypothesizedMean) / (s / Math.Sqrt(n));

            if (type == TTestHypotesis.MeanIsDifferentThanHypothesis)
            {
                PValue = 2.0 * StatisticDistribution.SurvivalFunction(Statistic);
                Hypothesis = Testing.Hypothesis.TwoTail;
            }
            else if (type == TTestHypotesis.MeanIsGreaterThanHypothesis)
            {
                PValue = StatisticDistribution.SurvivalFunction(Statistic);
                Hypothesis = Testing.Hypothesis.OneUpper;
            }
            else if (type == TTestHypotesis.MeanIsSmallerThanHypothesis)
            {
                PValue = StatisticDistribution.DistributionFunction(Statistic);
                Hypothesis = Testing.Hypothesis.OneLower;
            }
        }
Exemplo n.º 3
0
        public void DistributionFunctionTest()
        {
            TDistribution target = new TDistribution(1);
            double expected = 0.5;
            double actual = target.DistributionFunction(0);
            Assert.IsFalse(Double.IsNaN(actual));
            Assert.AreEqual(expected, actual, 1e-15);

            expected = 0.92559723470138278;
            actual = target.DistributionFunction(4.2);
            Assert.AreEqual(expected, actual);

            target = new TDistribution(2);
            expected = 0.5;
            actual = target.DistributionFunction(0);
            Assert.AreEqual(expected, actual);

            expected = 0.97385836652685043;
            actual = target.DistributionFunction(4.2);
            Assert.AreEqual(expected, actual);

            target = new TDistribution(3);
            expected = 0.5;
            actual = target.DistributionFunction(0);
            Assert.IsFalse(Double.IsNaN(actual));
            Assert.AreEqual(expected, actual, 1e-15);

            expected = 0.98768396091153043;
            actual = target.DistributionFunction(4.2);
            Assert.AreEqual(expected, actual);

            expected = 0.16324737815131229;
            actual = target.DistributionFunction(-1.17);
            Assert.AreEqual(expected, actual);
        }