Ejemplo n.º 1
0
        /// <summary>
        ///   Creates a new Anderson-Darling test.
        /// </summary>
        ///
        /// <param name="sample">The sample we would like to test as belonging to the <paramref name="hypothesizedDistribution"/>.</param>
        /// <param name="hypothesizedDistribution">A fully specified distribution.</param>
        ///
        public AndersonDarlingTest(double[] sample, IUnivariateDistribution <double> hypothesizedDistribution)
        {
            // Create the test statistic distribution
            this.TheoreticalDistribution = hypothesizedDistribution;
            if (hypothesizedDistribution is UniformContinuousDistribution)
            {
                StatisticDistribution = new AndersonDarlingDistribution(AndersonDarlingDistributionType.Uniform, sample.Length);
            }
            else if (hypothesizedDistribution is NormalDistribution)
            {
                StatisticDistribution = new AndersonDarlingDistribution(AndersonDarlingDistributionType.Normal, sample.Length);
            }
            else
            {
                Trace.WriteLine(String.Format("Unsupported distribution in AndersonDarling: {0}. P-values will not be computed, but test statistic may be useful.",
                                              hypothesizedDistribution.ToString(), hypothesizedDistribution.GetType().ToString()));
            }

            // Create a copy of the samples to prevent altering the
            // constructor's original arguments in the sorting step
            double[] sortedSamples = sample.Sorted();

            // Create the theoretical and empirical distributions
            this.TheoreticalDistribution = hypothesizedDistribution;

            this.Statistic = GetStatistic(sortedSamples, TheoreticalDistribution);
            this.PValue    = StatisticToPValue(Statistic);
        }