Accord.Statistics.Distributions.Univariate.ShapiroWilkDistribution.ShapiroWilkDistribution C# (CSharp) Method

ShapiroWilkDistribution() public method

Creates a new Shapiro-Wilk distribution.
public ShapiroWilkDistribution ( [ samples ) : System
samples [ The number of samples.
return System
        public ShapiroWilkDistribution([PositiveInteger(minimum: 4)] int samples)
        {
            if (samples < 4)
            {
                throw new ArgumentOutOfRangeException("samples",
                    "The number of samples must be higher than 3.");
            }

            this.NumberOfSamples = samples;

            if (samples <= 11)
            {
                double n = samples;
                double n2 = n * n;
                double n3 = n2 * n;

                double alpha = 0.459 * n - 2.273;
                this.g = w => -Math.Log(alpha - Math.Log(1 - w));
                this.h = w => Math.Exp(-Math.Exp(alpha)) * (Math.Exp(Math.Exp(-alpha)) - Math.Exp(w));
                double mean = -0.0006714 * n3 + 0.0250540 * n2 - 0.39978 * n + 0.54400;
                double sigma = Math.Exp(-0.0020322 * n3 + 0.0627670 * n2 - 0.77857 * n + 1.38220);

                this.normal = new NormalDistribution(mean, sigma);
            }
            else
            {
                double u = Math.Log(samples);
                double u2 = u * u;
                double u3 = u2 * u;

                this.g = w => Math.Log(1 - w);
                this.h = w => 1 - Math.Exp(w);
                double mean = 0.00389150 * u3 - 0.083751 * u2 - 0.31082 * u - 1.5861;
                double sigma = Math.Exp(0.00303020 * u2 - 0.082676 * u - 0.48030);

                this.normal = new NormalDistribution(mean, sigma);
            }
        }