コード例 #1
0
        public void ShapiroWilkTest()
        {
            // Tested against R's shapiro.test(x)

            double[] samples =
            {
                0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43, 
                0.21, 4.75, 0.71, 1.52, 3.24, 0.93, 0.42, 4.97,
                9.53, 4.55, 0.47, 6.66 
            };

            /* 
                samples <- c(0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43, 0.21,
                  + 4.75, 0.71, 1.52, 3.24, 0.93, 0.42, 4.97, 9.53, 4.55, 0.47, 6.66)
             
                shapiro.test(samples)
             
                W = 0.90050, p-value = 0.04209
             */

            var target = new ShapiroWilkTest(samples);

            Assert.AreEqual(0.90050, target.Statistic, 1e-4);
            Assert.AreEqual(0.04209, target.PValue, 1e-5);
        }
コード例 #2
0
        public void ShapiroWilkTest()
        {
            // Tested against R's shapiro.test(x)

            double[] samples =
            {
                0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43,
                0.21, 4.75, 0.71,  1.52, 3.24, 0.93, 0.42, 4.97,
                9.53, 4.55, 0.47, 6.66
            };

            /*
             *  samples <- c(0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43, 0.21,
             + 4.75, 0.71, 1.52, 3.24, 0.93, 0.42, 4.97, 9.53, 4.55, 0.47, 6.66)
             +
             +  shapiro.test(samples)
             +
             +  W = 0.90050, p-value = 0.04209
             */

            var target = new ShapiroWilkTest(samples);

            Assert.AreEqual(0.90050, target.Statistic, 1e-4);
            Assert.AreEqual(0.04209, target.PValue, 1e-5);
        }
コード例 #3
0
        public void RNGVentura_ShapiroWilkTest_Has_Significant_Deviation_From_Normal_Distribution()
        {
            double[] sample = GenerateFloatingPointNumberArray();

            var swTest = new ShapiroWilkTest(sample);

            // significant deviation from a normal distribution
            swTest.Significant.Should().BeTrue();
        }
コード例 #4
0
        protected override void EndProcessing()
        {
            var test = new ShapiroWilkTest(_data.ToArray())
            {
                Size = Size
            };

            WriteObject(test);
        }
コード例 #5
0
        public void ShapiroWilkTest()
        {
            // Tested against R's shapiro.test(x)

            #region doc_test
            // Let's say we would like to determine whether a set
            // of observations come from a normal distribution:
            double[] samples =
            {
                0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43,
                0.21, 4.75, 0.71,  1.52, 3.24, 0.93, 0.42, 4.97,
                9.53, 4.55, 0.47, 6.66
            };

            // For this, we can use the Shapiro-Wilk test. This test tests the null hypothesis
            // that samples come from a Normal distribution, vs. the alternative hypothesis that
            // the samples do not come from such distribution. In other words, should this test
            // come out significant, it means our samples do not come from a Normal distribution.

            // Create a new Shapiro-Wilk test:
            var sw = new ShapiroWilkTest(samples);

            double W           = sw.Statistic;   // should be 0.90050
            double p           = sw.PValue;      // should be 0.04209
            bool   significant = sw.Significant; // should be true

            // The test is significant, therefore we should reject the null
            // hypothesis that the samples come from a Normal distribution.
            #endregion

            /*
             *  samples <- c(0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43, 0.21,
             + 4.75, 0.71, 1.52, 3.24, 0.93, 0.42, 4.97, 9.53, 4.55, 0.47, 6.66)
             +
             +  shapiro.test(samples)
             +
             +  W = 0.90050, p-value = 0.04209
             */


            Assert.AreEqual(0.90050, W, 1e-4);
            Assert.AreEqual(0.04209, p, 1e-5);
            Assert.IsTrue(significant);
        }
コード例 #6
0
        public void ShapiroWilkTest2()
        {
            // Tested against R's shapiro.test(x)

            double[] samples =
            {
                1.36, 1.14, 2.92, 2.55, 1.46, 1.06, 5.27, 1.11, 3.48,
                1.10, 0.88, 0.51, 1.46, 0.52, 6.20, 1.69, 0.08, 3.67,
                2.81, 3.49
            };

            /*
             *  samples <- c(1.36, 1.14, 2.92, 2.55, 1.46, 1.06, 5.27, 1.11, 3.48, +
             *    1.10, 0.88, 0.51, 1.46, 0.52, 6.20, 1.69, 0.08, 3.67, 2.81, 3.49)
             *
             *  W = 0.89090000, p-value = 0.02798
             */

            var target = new ShapiroWilkTest(samples);

            Assert.AreEqual(0.89090, target.Statistic, 1e-4);
            Assert.AreEqual(0.02798, target.PValue, 1e-5);
        }
コード例 #7
0
        public void ShapiroWilkTest2()
        {
            // Tested against R's shapiro.test(x)

            double[] samples =
            {
                1.36, 1.14, 2.92, 2.55, 1.46, 1.06, 5.27, 1.11, 3.48,
                1.10, 0.88, 0.51, 1.46, 0.52, 6.20, 1.69, 0.08, 3.67,
                2.81, 3.49
            };

            /* 
                samples <- c(1.36, 1.14, 2.92, 2.55, 1.46, 1.06, 5.27, 1.11, 3.48, +
                  1.10, 0.88, 0.51, 1.46, 0.52, 6.20, 1.69, 0.08, 3.67, 2.81, 3.49)
             
                W = 0.89090000, p-value = 0.02798
             */

            var target = new ShapiroWilkTest(samples);

            Assert.AreEqual(0.89090, target.Statistic, 1e-4);
            Assert.AreEqual(0.02798, target.PValue, 1e-5);
        }
コード例 #8
0
        public void UniformDistributionTest(double[] sampleArr, double lowerBound, double upperBound)
        {
            Array.Sort(sampleArr);
            RunningStatistics runningStats = new RunningStatistics(sampleArr);

            // Skewness should be pretty close to zero (evenly distributed samples)
            if (Math.Abs(runningStats.Skewness) > 0.01) Assert.Fail();

            // Mean test.
            double range = upperBound - lowerBound;
            double expectedMean = lowerBound + (range / 2.0);
            double meanErr = expectedMean - runningStats.Mean;
            double maxExpectedErr = range / 1000.0;

            if (Math.Abs(meanErr) > maxExpectedErr) Assert.Fail();
            
            for (double tau = 0; tau <= 1.0; tau += 0.01)
            {
                double quantile = SortedArrayStatistics.Quantile(sampleArr, tau);
                double expectedQuantile = lowerBound + (tau * range);
                double quantileError = expectedQuantile - quantile;
                if (Math.Abs(quantileError) > maxExpectedErr) Assert.Fail();
            }

            ShapiroWilkTest test = new ShapiroWilkTest(sampleArr);
            Assert.True(test.Significant);
        }
コード例 #9
0
 public void TestBoxMullerTransformationClamped()
 {
     BoxMullerTransformation boxMullerTransformation = new BoxMullerTransformation(RandomGenerator.GetInstance());
     double[] values = Enumerable.Range(0, 1000000).Select(i => boxMullerTransformation.NextBoundedGaussian(3,2,10)).ToArray();
     ShapiroWilkTest test = new ShapiroWilkTest(values);
     Assert.True(test.Significant);
 }