Example #1
0
        public KS2(double[] valuesA, double[] valuesB, double binSize)
        {
            this.valuesA = valuesA;
            this.valuesB = valuesB;

            bins = KSTools.CreateBins(valuesA, valuesB, binSize);

            countsA = KSTools.GetHistogram(valuesA, bins);
            countsB = KSTools.GetHistogram(valuesB, bins);

            cphA = KSTools.CumulativeSum(countsA);
            cphB = KSTools.CumulativeSum(countsB);

            cphAbsDiff = KSTools.CreateKsLine(cphA, cphB);

            D = cphAbsDiff.Max() / 100.0;
            P = KSTools.CalculateKsP(D, valuesA.Length, valuesB.Length);
        }
Example #2
0
        private void BtnRun_Click(object sender, EventArgs e)
        {
            // BOOTSTRAP KS TEST
            double[] valuesA = valueSetA.values;
            double[] valuesB = valueSetB.values;
            double   binSize = (double)nudBinSize.Value;

            double[] bins = KSTools.CreateBins(valuesA, valuesB, binSize);

            int bootstrapCount = (int)nudRunCount.Value;
            int sampleSize     = (int)nudSampleSize.Value;

            double[] bootstrapDs = new double[bootstrapCount];
            double[] bootstrapPs = new double[bootstrapCount];

            progressBar1.Maximum = bootstrapCount;
            btnRun.Enabled       = false;
            for (int i = 0; i < bootstrapCount; i++)
            {
                progressBar1.Value = i + 1;
                progressBar1.Value = i;
                double[] cphA = KSTools.CumulativeSum(KSTools.GetHistogram(valueSetA.GetRandomSample(sampleSize), bins));
                double[] cphB = KSTools.CumulativeSum(KSTools.GetHistogram(valueSetB.GetRandomSample(sampleSize), bins));
                double   D    = KSTools.CalculateKsD(cphA, cphB);
                double   P    = KSTools.CalculateKsP(D, sampleSize, sampleSize);
                bootstrapDs[i] = D;
                bootstrapPs[i] = P;
            }
            progressBar1.Value = 0;
            btnRun.Enabled     = true;

            double meanD  = Meta.Numerics.Statistics.Univariate.Mean(bootstrapDs);
            double stdevD = Meta.Numerics.Statistics.Univariate.StandardDeviation(bootstrapDs);
            double meanP  = Meta.Numerics.Statistics.Univariate.Mean(bootstrapPs);
            double stdevP = Meta.Numerics.Statistics.Univariate.StandardDeviation(bootstrapPs);

            rtbBootstrapResults.Clear();
            rtbBootstrapResults.Text += string.Format("D = {0} +/- {1} ({2:0.00} %)\n", FormatNumber(meanD), FormatNumber(stdevD), 100 * stdevD / meanD);
            rtbBootstrapResults.Text += string.Format("P = {0} +/- {1}\n", FormatNumber(meanP), FormatNumber(stdevP));
            rtbBootstrapResults.Text += string.Format("P(D) = {0}", KSTools.CalculateKsP(meanD, sampleSize, sampleSize));
        }