Example #1
0
def confidence_interval(data, percentile, number_of_tails):
    """
       Computes confidence interval for the
       mean of the given data covering the probability given by the
       variable percentile.
       * data specifies the given data.
       * precentile gives the probability that the mean of the data is in
         the confidence interval.
       * number_of_tails gives the number of tails of the normal distribution
         to be considered.
    """
    square = math.pow(len(data), 0.5)
    mean = statchar.aritmetic_mean(data)
    std_dev = statchar.std_dev_corrected(data)
    dist = distributions.NormalDistribution(0, 1)
    if number_of_tails == 2:
        alfa = (1-percentile)/2
        c = distributions.find_percentile(1-alfa, dist.cdf)
        left = mean - c*std_dev/square
        right = mean + c*std_dev/square
        return left, right
    elif number_of_tails == 1:
        alfa = percentile
        c = distributions.find_percentile(alfa, dist.cdf)
        SEM = statchar.std_error_of_mean(data)
        left = mean
        right = mean + c*SEM/square
        return right
Example #2
0
    def test_results(self):
        list_1 = [1, 2, 3, 4, 5]

        result = statchar.std_dev_corrected(list_1)
        self.assertTrue(1.581 < result and result < 1.582)