コード例 #1
0
        public void ConstructorTest2()
        {
            var distribution = new NoncentralTDistribution(
                degreesOfFreedom: 4, noncentrality: 2.42);

            double mean   = distribution.Mean;                                    // 3.0330202123035104
            double median = distribution.Median;                                  // 2.6034842414893795
            double var    = distribution.Variance;                                // 4.5135883917583683

            double cdf  = distribution.DistributionFunction(x: 1.4);              // 0.15955740661144721
            double pdf  = distribution.ProbabilityDensityFunction(x: 1.4);        // 0.23552141805184526
            double lpdf = distribution.LogProbabilityDensityFunction(x: 1.4);     // -1.4459534225195116

            double ccdf = distribution.ComplementaryDistributionFunction(x: 1.4); // 0.84044259338855276
            double icdf = distribution.InverseDistributionFunction(p: cdf);       // 1.4000000000123853

            double hf  = distribution.HazardFunction(x: 1.4);                     // 0.28023498559521387
            double chf = distribution.CumulativeHazardFunction(x: 1.4);           // 0.17382662901507062

            string str = distribution.ToString(CultureInfo.InvariantCulture);     // T(x; df = 4, μ = 2.42)

            Assert.AreEqual(3.0330202123035104, mean);
            Assert.AreEqual(2.6034842414893795, median);
            Assert.AreEqual(4.5135883917583683, var);
            Assert.AreEqual(0.17382662901507062, chf);
            Assert.AreEqual(0.15955740661144721, cdf);
            Assert.AreEqual(0.23552141805184526, pdf);
            Assert.AreEqual(-1.4459534225195116, lpdf);
            Assert.AreEqual(0.28023498559521387, hf);
            Assert.AreEqual(0.84044259338855276, ccdf);
            Assert.AreEqual(1.4000000000123853, icdf);
            Assert.AreEqual("T(x; df = 4, μ = 2.42)", str);
        }
コード例 #2
0
        /// <summary>
        ///  Computes the power for a test with givens values of
        ///  <see cref="IPowerAnalysis.Effect">effect size</see> and <see cref="IPowerAnalysis.Samples">
        ///  number of samples</see> under <see cref="IPowerAnalysis.Size"/>.
        /// </summary>
        ///
        /// <returns>
        ///  The power for the test under the given conditions.
        /// </returns>
        ///
        public override void ComputePower()
        {
            double delta = Effect / Math.Sqrt(1.0 / Samples1 + 1.0 / Samples2);
            double df    = Samples1 + Samples2 - 2;

            TDistribution           td = new TDistribution(df);
            NoncentralTDistribution nt = new NoncentralTDistribution(df, delta);

            switch (Tail)
            {
            case DistributionTail.TwoTail:
            {
                double Ta = td.InverseDistributionFunction(1.0 - Size / 2);
                double pa = nt.ComplementaryDistributionFunction(+Ta);
                double pb = nt.DistributionFunction(-Ta);
                Power = pa + pb;
                break;
            }

            case DistributionTail.OneLower:
            {
                double Ta = td.InverseDistributionFunction(Size);
                Power = nt.DistributionFunction(Ta);
                break;
            }

            case DistributionTail.OneUpper:
            {
                double Ta = td.InverseDistributionFunction(1.0 - Size);
                Power = nt.ComplementaryDistributionFunction(Ta);
                break;
            }

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #3
0
        public void ConstructorTest2()
        {
            var distribution = new NoncentralTDistribution(
                degreesOfFreedom: 4, noncentrality: 2.42);

            double mean   = distribution.Mean;                                    // 3.0330202123035104
            double median = distribution.Median;                                  // 2.6034842414893795
            double var    = distribution.Variance;                                // 4.5135883917583683
            double mode   = distribution.Mode;                                    // 2.0940683409246641

            double cdf  = distribution.DistributionFunction(x: 1.4);              // 0.15955740661144721
            double pdf  = distribution.ProbabilityDensityFunction(x: 1.4);        // 0.23552141805184526
            double lpdf = distribution.LogProbabilityDensityFunction(x: 1.4);     // -1.4459534225195116

            double ccdf = distribution.ComplementaryDistributionFunction(x: 1.4); // 0.84044259338855276
            double icdf = distribution.InverseDistributionFunction(p: cdf);       // 1.4000000000123853

            double hf  = distribution.HazardFunction(x: 1.4);                     // 0.28023498559521387
            double chf = distribution.CumulativeHazardFunction(x: 1.4);           // 0.17382662901507062

            string str = distribution.ToString(CultureInfo.InvariantCulture);     // T(x; df = 4, μ = 2.42)

            Assert.AreEqual(3.0330202123035104, mean);
            Assert.AreEqual(2.6034842414893795, median);
            Assert.AreEqual(4.5135883917583683, var);
            Assert.AreEqual(2.0940683409246641, mode);
            Assert.AreEqual(0.17382662901507062, chf);
            Assert.AreEqual(0.15955740661144721, cdf);
            Assert.AreEqual(0.23552141805184526, pdf);
            Assert.AreEqual(-1.4459534225195116, lpdf);
            Assert.AreEqual(0.28023498559521387, hf);
            Assert.AreEqual(0.84044259338855276, ccdf);
            Assert.AreEqual(1.4000000000123853, icdf);
            Assert.AreEqual("T(x; df = 4, μ = 2.42)", str);

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

            Assert.AreEqual(0.7641009341279591, range1.Min);
            Assert.AreEqual(6.6668131011180742, range1.Max);
            Assert.AreEqual(0.098229727233034247, range2.Min);
            Assert.AreEqual(10.541194525031729, range2.Max);
            Assert.AreEqual(0.09822972723303551, range3.Min);
            Assert.AreEqual(10.541194525031729, range3.Max);
        }