SurvivalFunction() public method

Gets the complementary cumulative distribution function for the χ² evaluated at point x.
public SurvivalFunction ( double x ) : double
x double
return double
Ejemplo n.º 1
0
        /// <summary>
        ///   Constructs a Chi-Square Test.
        /// </summary>
        /// <param name="statistic">The test statistic.</param>
        /// <param name="degreesOfFreedom">The chi-square distribution degrees of freedom.</param>
        /// <param name="threshold">The significance threshold. By default, 0.05 will be used.</param>
        /// 
        public ChiSquareTest(double statistic, int degreesOfFreedom, double threshold)
        {
            this.Statistic = statistic;
            this.Threshold = threshold;
            this.distribution = new ChiSquareDistribution(degreesOfFreedom);

            this.PValue = distribution.SurvivalFunction(Statistic);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Construct a Chi-Square Test.
        /// </summary>
        /// <param name="expected">The expected variable values.</param>
        /// <param name="observed">The observed variable values.</param>
        /// <param name="degreesOfFreedom">The chi-square distribution degrees of freedom.</param>
        /// <param name="threshold">The significance threshold. By default, 0.05 will be used.</param>
        /// 
        public ChiSquareTest(double[] expected, double[] observed, int degreesOfFreedom, double threshold)
        {
            if (expected == null)
                throw new ArgumentNullException("expected");

            if (observed == null)
                throw new ArgumentNullException("observed");

            // X² = sum(o - e)²
            //          -----
            //            e

            double sum = 0.0;
            for (int i = 0; i < observed.Length; i++)
            {
                double d = observed[i] - expected[i];
                sum += (d * d) / expected[i];
            }

            this.Statistic = sum;
            this.Threshold = threshold;
            this.distribution = new ChiSquareDistribution(degreesOfFreedom);

            this.PValue = distribution.SurvivalFunction(Statistic);
        }