Ejemplo n.º 1
0
        /// <summary>
        ///   Tests the null hypothesis that the population mean is equal to a specified value.
        /// </summary>
        /// 
        public TTest(double[] sample, double hypothesizedMean, TTestHypotesis type)
        {
            int n = sample.Length;
            double x = Accord.Statistics.Tools.Mean(sample);
            double s = Accord.Statistics.Tools.StandardDeviation(sample, x);

            StatisticDistribution = new TDistribution(n - 1);
            Statistic = (x - hypothesizedMean) / (s / Math.Sqrt(n));

            if (type == TTestHypotesis.MeanIsDifferentThanHypothesis)
            {
                PValue = 2.0 * StatisticDistribution.SurvivalFunction(Statistic);
                Hypothesis = Testing.Hypothesis.TwoTail;
            }
            else if (type == TTestHypotesis.MeanIsGreaterThanHypothesis)
            {
                PValue = StatisticDistribution.SurvivalFunction(Statistic);
                Hypothesis = Testing.Hypothesis.OneUpper;
            }
            else if (type == TTestHypotesis.MeanIsSmallerThanHypothesis)
            {
                PValue = StatisticDistribution.DistributionFunction(Statistic);
                Hypothesis = Testing.Hypothesis.OneLower;
            }
        }