Exemplo n.º 1
0
        /// <summary>
        /// Two-sided or one-sided test for a single mean
        ///
        /// A two-sided hypothesis with threshold of alpha (i.e. significance level) is equivalent to a confidence interval of CL (i.e. confidence level) = 1 - alpha
        /// A one-sided hypothesis with threshold of alpha is equivalent to a confidence interval of CL = 1 - alpha * 2
        ///
        /// If H_0 is rejected, a confidence interval that agrees with the result of the hypothesis test should not include the null_value
        /// If H_0 is failed to be rejected, a confidence interval that agrees with the result of the hypothesis should include the null_value
        /// </summary>
        /// <param name="values">value sample for the varabiel</param>
        /// <param name="null_value">The null hypothesis value that true population mean, mu = null_value</param>
        /// <param name="significance_level"></param>
        /// <param name="one_sided">True if the test is one-sided</param>
        /// <returns>True if the null hypothesis H_0 : (mu == null_value) is rejected</returns>
        public bool RejectH0_ByCI(double[] values, double null_value, double significance_level = 0.05, bool one_sided = false)
        {
            double confidence_level = 1 - significance_level * (one_sided ? 2 : 1);

            double[] confidence_interval = ConfidenceInterval.GetConfidenceInterval(values, confidence_level);
            return(null_value < confidence_interval[0] || null_value > confidence_interval[1]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Two-sided test for whether statitics of two variables are equal in the true population, var1 and var2 are independent
        ///
        /// Hypotheses are:
        /// H_0: mu_var1 = mu_var2
        /// H_1: mu_var1 != mu_var2
        ///
        /// The hypotheses can be written as
        /// H_0: mu_var1 - mu_var2 = 0
        /// H_1: mu_var1 - mu_var2 != 0
        ///
        /// By Central Limt Theorem:
        /// sample_mean_var1 - sample_mean_var2 ~ N(0, SE), where null_value = 0 and SE is the standard error of the sampling distribution
        /// </summary>
        /// <param name="sample_for_var1">value sample for variable 1</param>
        /// <param name="sample_for_var2">value sample for variable 2</param>
        /// <param name="significance_level"></param>
        /// <returns></returns>
        public bool RejectH0_ByCI(double[] sample_for_var1, double[] sample_for_var2, double significance_level = 0.05, bool one_sided = false)
        {
            double confidence_level = 1 - significance_level * (one_sided ? 2 : 1);

            double[] confidence_interval = ConfidenceInterval.GetConfidenceIntervalForDiff(sample_for_var1, sample_for_var2, confidence_level);
            double   null_value          = 0;

            return(null_value < confidence_interval[0] || null_value > confidence_interval[1]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Two-sided or one-sided test for whether statitics of two variables are equal in the true population, var1 and var2 are paired and dependent
        ///
        /// Hypotheses are:
        /// H_0: mu_var1 = mu_var2
        /// H_1: mu_var1 != mu_var2
        ///
        /// The hypotheses can be written as
        /// H_0: mu_var1 - mu_var2 = 0
        /// H_1: mu_var1 - mu_var2 != 0
        ///
        /// By Central Limt Theorem:
        /// sample_mean_var1 - sample_mean_var2 ~ N(0, SE), where null_value = 0 and SE is the standard error of the sampling distribution
        /// </summary>
        /// <param name="sample_for_paired_data">a random sample consisting data paired together, var1 and var2, var1 and var2 are not independent</param>
        /// <param name="one_sided">True if the test is one-sided</param>
        /// <param name="significance_level"></param>
        /// <returns></returns>
        public bool RejectH0_PairedData_ByCI(Tuple <double, double>[] sample_for_paired_data, double significance_level = 0.05, bool one_sided = false)
        {
            int sample_size = sample_for_paired_data.Length;

            double[] diff = new double[sample_size];
            for (int i = 0; i < sample_size; ++i)
            {
                diff[i] = sample_for_paired_data[i].Item1 - sample_for_paired_data[i].Item2;
            }
            double confidence_level = 1 - significance_level * (one_sided ? 2 : 1);

            double[] confidence_interval = ConfidenceInterval.GetConfidenceInterval(diff, confidence_level);
            double   null_value          = 0;

            return(null_value < confidence_interval[0] || null_value > confidence_interval[1]);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Check whether variable 1 is truely less than variable 2 at 0.95 statistical significance confidence level
 /// </summary>
 /// <param name="sample_for_var1">value sample for variable 1</param>
 /// <param name="sample_for_var2">value sample for variable 2</param>
 /// <param name="confidence_level"></param>
 /// <returns></returns>
 public bool AreLessThan(double[] sample_for_var1, double[] sample_for_var2, double confidence_level = 0.95)
 {
     double[] confidence_interval_for_var1 = ConfidenceInterval.GetConfidenceInterval(sample_for_var1, confidence_level);
     double[] confidence_interval_for_var2 = ConfidenceInterval.GetConfidenceInterval(sample_for_var2, confidence_level);
     return(confidence_interval_for_var1[1] < confidence_interval_for_var2[0]);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Check whether variable 1 is truely greater than variable 2 at 0.95 statistical significance confidence level, var1 and var2 are independent
 /// </summary>
 /// <param name="sample_for_var1">value sample for variable 1</param>
 /// <param name="sample_for_var2">value sample for variable 2</param>
 /// <param name="confidence_level"></param>
 /// <returns></returns>
 public bool AreGreater(double[] sample_for_var1, double[] sample_for_var2, double confidence_level = 0.95)
 {
     double[] confidence_interval_for_var1 = ConfidenceInterval.GetConfidenceInterval(sample_for_var1, confidence_level);
     double[] confidence_interval_for_var2 = ConfidenceInterval.GetConfidenceInterval(sample_for_var2, confidence_level);
     return(confidence_interval_for_var1[0] > confidence_interval_for_var2[1]);
 }