Exemplo n.º 1
0
        public void QuantileR2InverseCDFAverageOnShortSequence(double tau, double expected)
        {
            // R: quantile(c(-1,5,0,-3,10,-0.5,4,0.2,1,6),probs=c(0,1,0.5,0.2,0.7,0.01,0.99,0.52,0.325),type=2)
            // Mathematica: Not Supported

            var samples = new[] { -1, 5, 0, -3, 10, -0.5, 4, 0.2, 1, 6 };

            Assert.AreEqual(expected, Statistics.QuantileCustom(samples, tau, QuantileDefinition.R2), 1e-14);
            Assert.AreEqual(expected, Statistics.QuantileCustomFunc(samples, QuantileDefinition.R2)(tau), 1e-14);

            Assert.AreEqual(expected, ArrayStatistics.QuantileCustomInplace(samples, tau, QuantileDefinition.InverseCDFAverage), 1e-14);

            Array.Sort(samples);
            Assert.AreEqual(expected, SortedArrayStatistics.QuantileCustom(samples, tau, QuantileDefinition.InverseCDFAverage), 1e-14);
        }
Exemplo n.º 2
0
        public void QuantileR9NormalOnShortSequence(double tau, double expected)
        {
            // R: quantile(c(-1,5,0,-3,10,-0.5,4,0.2,1,6),probs=c(0,1,0.5,0.2,0.7,0.01,0.99,0.52,0.325),type=9)
            // Mathematica: Quantile[{-1,5,0,-3,10,-1/2,4,1/5,1,6},{0,1,1/2,1/5,7/10,1/100,99/100,13/25,13/40},{{3/8,1/4},{0,1}}]
            var samples = new[] { -1, 5, 0, -3, 10, -0.5, 4, 0.2, 1, 6 };

            Assert.AreEqual(expected, Statistics.QuantileCustom(samples, tau, QuantileDefinition.R9), 1e-14);
            Assert.AreEqual(expected, Statistics.QuantileCustomFunc(samples, QuantileDefinition.R9)(tau), 1e-14);

            Assert.AreEqual(expected, ArrayStatistics.QuantileCustomInplace(samples, tau, QuantileDefinition.Normal), 1e-14);
            Assert.AreEqual(expected, ArrayStatistics.QuantileCustomInplace(samples, tau, 3 / 8d, 1 / 4d, 0d, 1d), 1e-14);

            Array.Sort(samples);
            Assert.AreEqual(expected, SortedArrayStatistics.QuantileCustom(samples, tau, QuantileDefinition.Normal), 1e-14);
            Assert.AreEqual(expected, SortedArrayStatistics.QuantileCustom(samples, tau, 3 / 8d, 1 / 4d, 0d, 1d), 1e-14);
        }