Ejemplo n.º 1
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("");
        }
Ejemplo n.º 2
0
        public void TestAlignmentPValue(string basePath, string name)
        {
            RootDataPath = basePath;

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

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

            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;
            }

            var test = HypothesisTestingFactory.CreateTests(HypothesisTests.MannWhitneyU);
            var data = test.Test(preDist, postDist);

            Print(string.Format("Two Tail - {0} ", data.TwoTail));
            Print(string.Format("Left Tail - {0} ", data.LeftTail));
            Print(string.Format("Right Tail - {0} ", data.RightTail));
        }