Beispiel #1
0
        public static IHypothesisTestingTwoSample CreateTests(HypothesisTests test)
        {
            IHypothesisTestingTwoSample newTest = null;

            switch (test)
            {
            case HypothesisTests.TTest:
                newTest = new StudentTTest();
                break;

            case HypothesisTests.MannWhitneyU:
                newTest = new MannWhitneyTest();
                break;

            case HypothesisTests.KolmogorovSmirnov:
                newTest = new KolmogorovSmirnovTest();
                break;
            }

            return(newTest);
        }
        /// <summary>
        ///     Calculates the p-value until statistically insignificant or past a number of iterations (100);
        /// </summary>
        /// <param name="preDist"></param>
        /// <param name="postDist"></param>
        /// <param name="testType"></param>
        private void TestAlignmentPValueToFailure(List<double> preDist, List<double> postDist, HypothesisTests testType,
            double step)
        {
            double pValue = 0;
            var nIterations = 0;
            double shift = 0;
            Print("Mean-Pre, Mean Post, Shift Amount, Mean Diff, p-Value two, left, right");
            var meanPost = postDist.Average();

            var postHistogram = new Histogram(.002, -.05, .05, "post-alignment");
            postHistogram.AddData(postDist);
            var histograms = new List<Histogram>();
            histograms.Add(postHistogram);
            while (pValue < .05 && nIterations < 100)
            {
                var newPre = new List<double>();
                preDist.ForEach(x => newPre.Add(x + shift));
                var mean = newPre.Average();

                var test = HypothesisTestingFactory.CreateTests(testType);
                var data = test.Test(newPre, postDist);
                Print(string.Format("{0},{1},{2},{3},{4},{5},{5}", mean, meanPost, shift, Math.Abs(mean - meanPost),
                    data.TwoTail, data.LeftTail, data.RightTail));

                var preHistogram = new Histogram(.002, -.05, .05, string.Format("{0:.0000}", mean));
                preHistogram.AddData(newPre);
                histograms.Add(preHistogram);

                pValue = data.TwoTail;
                nIterations++;
                shift += step;
            }

            var originalPreHistogram = new Histogram(.002, -.05, .05, "pre-histogram");
            originalPreHistogram.AddData(preDist);
            Print("");
            PrintHistogram(originalPreHistogram);
            Print("");
            PrintHistogram(postHistogram);
            Print("");
            PrintHistogram("pre-post", histograms);
            Print("");
        }
        public void TestAlignmentPValueToFailure(string basePath, string name, double step, HypothesisTests testType)
        {
            RootDataPath = basePath;

            var preDist = new List<double>();
            var postDist = new List<double>();

            var lines = File.ReadAllLines(Path.Combine(basePath, name));
            var header = true;

            Print(string.Format("TEST: {1} - {0}", name, testType));
            Print("");

            foreach (var line in lines)
            {
                if (!header)
                {
                    var stringData = line.Split(',');
                    if (stringData.Length > 2)
                    {
                        var preValue = Convert.ToDouble(stringData[1]);
                        var postValue = Convert.ToDouble(stringData[2]);

                        //if (Math.Abs(preValue) < .05)
                        {
                            preDist.Add(preValue);
                        }

                        //if (Math.Abs(postValue ) < .05)
                        {
                            postDist.Add(postValue);
                        }
                    }
                }
                header = false;
            }

            TestAlignmentPValueToFailure(preDist, postDist, testType, step);
        }
Beispiel #4
0
        /// <summary>
        ///     Calculates the p-value until statistically insignificant or past a number of iterations (100);
        /// </summary>
        /// <param name="preDist"></param>
        /// <param name="postDist"></param>
        /// <param name="testType"></param>
        private void TestAlignmentPValueToFailure(List <double> preDist, List <double> postDist, HypothesisTests testType,
                                                  double step)
        {
            double pValue      = 0;
            var    nIterations = 0;
            double shift       = 0;

            Print("Mean-Pre, Mean Post, Shift Amount, Mean Diff, p-Value two, left, right");
            var meanPost = postDist.Average();


            var postHistogram = new Histogram(.002, -.05, .05, "post-alignment");

            postHistogram.AddData(postDist);
            var histograms = new List <Histogram>();

            histograms.Add(postHistogram);
            while (pValue < .05 && nIterations < 100)
            {
                var newPre = new List <double>();
                preDist.ForEach(x => newPre.Add(x + shift));
                var mean = newPre.Average();

                var test = HypothesisTestingFactory.CreateTests(testType);
                var data = test.Test(newPre, postDist);
                Print(string.Format("{0},{1},{2},{3},{4},{5},{5}", mean, meanPost, shift, Math.Abs(mean - meanPost),
                                    data.TwoTail, data.LeftTail, data.RightTail));

                var preHistogram = new Histogram(.002, -.05, .05, string.Format("{0:.0000}", mean));
                preHistogram.AddData(newPre);
                histograms.Add(preHistogram);

                pValue = data.TwoTail;
                nIterations++;
                shift += step;
            }

            var originalPreHistogram = new Histogram(.002, -.05, .05, "pre-histogram");

            originalPreHistogram.AddData(preDist);
            Print("");
            PrintHistogram(originalPreHistogram);
            Print("");
            PrintHistogram(postHistogram);
            Print("");
            PrintHistogram("pre-post", histograms);
            Print("");
        }
Beispiel #5
0
        public void TestAlignmentPValueToFailure(string basePath, string name, double step, HypothesisTests testType)
        {
            RootDataPath = basePath;

            var preDist  = new List <double>();
            var postDist = new List <double>();

            var lines  = File.ReadAllLines(Path.Combine(basePath, name));
            var header = true;

            Print(string.Format("TEST: {1} - {0}", name, testType));
            Print("");

            foreach (var line in lines)
            {
                if (!header)
                {
                    var stringData = line.Split(',');
                    if (stringData.Length > 2)
                    {
                        var preValue  = Convert.ToDouble(stringData[1]);
                        var postValue = Convert.ToDouble(stringData[2]);

                        //if (Math.Abs(preValue) < .05)
                        {
                            preDist.Add(preValue);
                        }

                        //if (Math.Abs(postValue ) < .05)
                        {
                            postDist.Add(postValue);
                        }
                    }
                }
                header = false;
            }


            TestAlignmentPValueToFailure(preDist, postDist, testType, step);
        }