public void TTest()
 {
     TTestResult ttest = BasicStatisticalFormulas.TTestEqualVariances(this.AssociatedObject.meandiff.Value, 0.1, this.AssociatedObject.series1, this.AssociatedObject.series2);
     this.AssociatedObject.result.Text = "T Value = " + ttest.TValue.ToString() + "\n" +
                     "T Critical Value one Tail = " + ttest.TCriticalValueOneTail.ToString() + "\n" +
                     "T Critical value two Tail = " + ttest.TCriticalValueTwoTail.ToString() + "\n" +
                     "Probability T One Tail = " + ttest.ProbabilityTOneTail.ToString() + "\n" +
                     "Probability T Two Tail = " + ttest.ProbabilityTTwoTail.ToString() + "\n" +
                     "First Series Mean = " + ttest.FirstSeriesMean.ToString() + "\n" +
                     "First Series Variance = " + ttest.FirstSeriesVariance.ToString() + "\n" +
                     "Second Series Mean = " + ttest.SecondSeriesMean.ToString() + "\n" +
                     "Second Series Variance =" + ttest.SecondSeriesVariance.ToString() + "\n";
 }
Beispiel #2
0
        private void tryTAndFTest(String mode)
        {
            if (modeFirst.Equals("") | modeFirst.Equals(mode))
            {
                modeFirst = mode;
                return;
            }



            TTestResult resultTTest = dummyChart.DataManipulator.Statistics.TTestPaired(0.3, 0.05, modeFirst, mode);

            textBox_Results.AppendText("\r\nTTest for " + modeFirst + "\r\nand " + mode + "\r\nis " + resultTTest.TValue);
            textBox_Results.AppendText("\r\nProbability: " + resultTTest.ProbabilityTOneTail);
            textBox_Results.AppendText("\r\nCritical TValue: " + resultTTest.TCriticalValueOneTail);

            FTestResult resultFTest = dummyChart.DataManipulator.Statistics.FTest(0.05, modeFirst, mode);

            textBox_Results.AppendText("\r\nFTest for " + modeFirst + "\r\nand " + mode + "\r\nis " + resultFTest.FValue);
            textBox_Results.AppendText("\r\nProbability: " + resultFTest.ProbabilityFOneTail);
            textBox_Results.AppendText("\r\nCritical FValue: " + resultFTest.FCriticalValueOneTail);

            modeFirst = "";
        }
Beispiel #3
0
        public static TTestResult TTest(double[] x, double[] y)
        {
            TTestResult result = new TTestResult();
            // Welch's t-test for two samples
            double sumX = 0.0; // calculate means
            double sumY = 0.0;

            for (int i = 0; i < x.Length; ++i)
            {
                sumX += x[i];
            }

            for (int i = 0; i < y.Length; ++i)
            {
                sumY += y[i];
            }

            int    n1    = x.Length;
            int    n2    = y.Length;
            double meanX = sumX / n1;
            double meanY = sumY / n2;

            double sumXminusMeanSquared = 0.0; // calculate (sample) variances
            double sumYminusMeanSquared = 0.0;

            for (int i = 0; i < n1; ++i)
            {
                sumXminusMeanSquared += (x[i] - meanX) * (x[i] - meanX);
            }

            for (int i = 0; i < n2; ++i)
            {
                sumYminusMeanSquared += (y[i] - meanY) * (y[i] - meanY);
            }

            double varX = sumXminusMeanSquared / (n1 - 1);
            double varY = sumYminusMeanSquared / (n2 - 1);

            // t statistic
            double top = (meanX - meanY);
            double bot = Math.Sqrt((varX / n1) + (varY / n2));
            double t   = top / bot;


            // df mildly tricky
            // http://www.statsdirect.com/help/default.htm#parametric_methods/unpaired_t.htm
            double num = ((varX / n1) + (varY / n2)) *
                         ((varX / n1) + (varY / n2));
            double denomLeft  = ((varX / n1) * (varX / n1)) / (n1 - 1);
            double denomRight = ((varY / n2) * (varY / n2)) / (n2 - 1);
            double denom      = denomLeft + denomRight;
            double df         = num / denom;

            double p = Student(t, df); // cumulative two-tail density

            System.Diagnostics.Debug.WriteLine("mean of x = " + meanX.ToString("F2"));
            System.Diagnostics.Debug.WriteLine("mean of y = " + meanY.ToString("F2"));
            System.Diagnostics.Debug.WriteLine("t (t-統計)= " + t.ToString("F4"));
            System.Diagnostics.Debug.WriteLine("df (自由度) = " + df.ToString("F3"));
            System.Diagnostics.Debug.WriteLine("p-value (顯著性) = " + p.ToString("F5"));
            result.df    = df;
            result.p     = p;
            result.t     = t;
            result.meanX = meanX;
            result.meanY = meanY;
            Explain();
            return(result);
        }