Esempio n. 1
0
def confidence_interval(numbers):
    m = mean(numbers)
    confidence_level = 0.95
    z = (1-confidence_level) / 2
    sd = standard_deviation(numbers)
    n = squareroot(len(numbers))
    return [subtraction(multiplication(division(n, sd), z), m), addition(multiplication(division(n, sd), z), m)]
def sample_size_unknown_pop(confidence_level, width):
    p = 0.5
    q = 1 - p

    return round(
        multiplication(
            square(
                division(division(2, width),
                         calculate_zvalue(confidence_level))),
            multiplication(p, q)), 2)
Esempio n. 3
0
def cochran(p, q, z, e):
    try:
        n1 = multiplication(p, p)
        n2 = z * z
        n3 = multiplication(n1, n2)
        n4 = e * e
        nCochran = division(n4, n3)
        return int(nCochran)
    except ZeroDivisionError:
        print("Error: Can't Divide by 0")
    except ValueError:
        print("Error: Check your data inputs")
Esempio n. 4
0
def population_correlation_coefficient(list_x, list_y):
    total = 0
    x = standard_deviation(list_x)
    y = standard_deviation(list_y)
    for i in range(len(list_x)):
        diff_x = subtraction(list_x[i], mean(list_x))
        diff_y = subtraction(list_y[i], mean(list_y))
        total = total + multiplication(division(diff_x, x), division(
            diff_y, y))
    return round(
        float(
            multiplication(division(1, addition(len(list_x), len(list_y))),
                           total)), 4)
Esempio n. 5
0
def cochran(sample, confidence_level):
    # Validations
    check_for_valid_numbers(sample)
    empty_list_check(sample)

    # Formula: (Z^2)(p)(q) / (e^2) -> https://www.statisticshowto.com/probability-and-statistics/find-sample-size/
    # Assuming p is 0.5

    # calculate z from a given confidence interval
    z = CalculateZValue.calculate_zvalue(confidence_level)

    margin_of_error_result = square(margin_of_error(sample, confidence_level))
    return division(margin_of_error_result,
                    multiplication(multiplication(square(z), 0.5), 0.5))
def variance_of_population_proportion(numbers):
    n = len(numbers)
    prop = proportion(numbers)
    prop_2 = subtraction(prop, 1)
    x = multiplication(prop, prop_2)
    variance_of_pp = division(x, n)
    return variance_of_pp
Esempio n. 7
0
def Pop_correlation_coefficient():
    lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    x_data = [1, 25, 34, 4, 51]
    y_data = [6, 7, 8, 9, 10]
    x_mean = mean(x_data)
    y_mean = mean(y_data)
    a = []
    b = []
    ab = []
    x = st_dev(x_data)
    y = st_dev(y_data)
    divisor = multiplication(x, y)
    z = len(lst)

    for i in x_data:
        new1 = subtraction(x_mean, i)
        zx = division(new1, x)
        a.append(zx)

        # (zx)i = (xi – x̄) / s x
    for i in y_data:
        new2 = subtraction(y_mean, i)
        zy = division(new2, y)
        b.append(zy)

    ab = [a[i] * b[i] for i in range(len(x_data))]

    tot_sum = sum(ab)
    result = tot_sum / 4

    return result
def Pop_correlation_coefficient(x_data, y_data):
    x_mean = mean(x_data)
    y_mean = mean(y_data)
    a = []
    b = []
    tot_sum = 0
    x = st_dev(x_data)
    y = st_dev(y_data)

    for i in x_data:
        new1 = subtraction(x_mean, i)
        zx = division(new1, x)
        a.append(zx)

    for i in y_data:
        new2 = subtraction(y_mean, i)
        zy = division(new2, y)
        b.append(zy)

    for i in range(len(x_data)):
        ab = multiplication(a[i], b[i])
        tot_sum = addition(tot_sum, ab)

    cal_result = division(tot_sum, subtraction(1, len(x_data)))

    return cal_result
def variance_samp_prop(numbers):
    ran = random.randint(1, len(numbers))
    values = getSample(numbers, ran)
    p = proportion(values)
    m = multiplication(p, subtraction(p, 1))
    x = subtraction(len(values), 1)
    h = division(x, m)
    return h
Esempio n. 10
0
def v_samp_proportion(lst):
    ss = random.randint(1, len(lst))
    new_values = getSample(lst, ss)
    p = proportion(new_values)
    c = multiplication(p, subtraction(p, 1))
    y = subtraction(len(new_values), 1)
    x = division(c, y)
    return x
Esempio n. 11
0
def confidenceinterval(lst, conf):
    x = mean(lst)
    std = standard_deviation(lst)
    if conf == 95:
        t = 1.96
    elif conf == 90:
        t = 1.64
    elif conf == 99:
        t = 2.58
    else:  # 95 default confidence percentage
        t = 1.96

    std_error = division(std, root(len(lst)))
    conf_upper = addition(x, multiplication(t, std_error))
    conf_upper = round(conf_upper, 2)
    conf_lower = subtraction(multiplication(t, std_error), x)
    conf_lower = round(conf_lower, 2)
    return conf_upper, conf_lower
def confidence_interval(data):
    z_value = 1.05
    mean =sample_mean(data)
    sd = pop_standard_dev(data)
    x = len(data)
    y = division(squareroot(x), sd)
    margin_of_error = multiplication(z_value, y)
    a = subtraction(mean, margin_of_error)
    b = addition(mean, margin_of_error)
    return a, b
Esempio n. 13
0
def var_sample_proportion(data):
    sample_data = data[0:999]
    sample_prop_data = []
    for x in sample_data:
        if x > 64:
            sample_prop_data.append(x)
    sample_len = len(sample_prop_data)
    sample_len_data = len(sample_data)
    p = round(sample_len / sample_len_data, 6)
    q = subtraction(1, p)
    return round(multiplication(p, q) / (sample_len_data - 1), 6)
def cimarginerror(n, x, s):
    try:
        zValue = 1.96
        n1 = square_root(n)
        n2 = division(n1, s)
        n3 = multiplication(n2, zValue)
        return round(float(n3), 2)
    except ZeroDivisionError:
        print("Error: Can't Divide by 0")
    except ValueError:
        print("Error: Check your data inputs")
Esempio n. 15
0
def margin_of_error(sample, confidence_level):
    # Validations
    empty_list_check(sample)
    check_for_valid_numbers(sample)

    # Formula - z * (o /  sqrt(n)); o is our standard deviation
    # Reference - https://www.surveymonkey.com/mp/margin-of-error-calculator/
    z = CalculateZValue.calculate_zvalue(confidence_level)
    sample_size = len(sample)
    standard_deviation_result = standard_deviation(sample)
    return multiplication(
        z, division(square_root(sample_size), standard_deviation_result))
Esempio n. 16
0
    def correlation(data1, data2, seed):
        # population sample with seed
        pop1 = ItemReturnType.aList_seed(data1, 5, seed)
        pop2 = ItemReturnType.aList_seed(data2, 5, seed)

        cv = Covariance.covariance(pop1, pop2)

        stdDev1 = StandardDeviation.standard_deviance(pop1)
        stdDev2 = StandardDeviation.standard_deviance(pop2)

        sc = cv / (multiplication(stdDev1, stdDev2))

        return sc
Esempio n. 17
0
def confidence_intervals(data):
    try:
        zvalue = 1.960
        nLenght = len(data)
        nMean = mean(data)
        sd = stddev(data)
        pprint(sd)
        CI = multiplication(zvalue, (division(square_root(nLenght), sd)))
        x = round(float(CI), 1)
        pprint(str(str(nMean) + "+" + str(x)))
        return str(str(nMean) + "+" + str(x))
    except ZeroDivisionError:
        print("Error: Can't Divide by 0")
    except ValueError:
        print("Error: Check your data inputs")
Esempio n. 18
0
def confidence_interval(data):
    z_value = 1.960
    mean = population_mean(data)
    sd = pop_stand_dev(data)

    x = len(data)
    y = division(sq_rt(x), sd)

    margin_of_error = multiplication(z_value, y)

    a = [subtraction(mean, margin_of_error)]
    b = [addition(mean, margin_of_error)]

    size = len(a)
    lower = a[0]
    upper = b[0]

    return lower, upper
Esempio n. 19
0
def sample_correlation(data, data1):
    try:

        mean1 = mean(data)
        mean2 = mean(data1)
        List1 = []
        List2 = []

        for num in data:
            a = subtraction(int(round(mean1, 0)), num)
            List1.append(a)

        for num in data1:
            b = subtraction(mean2, num)
            List2.append(b)
        c = np.multiply(List1, List2)
        cc = 0
        for num in c:
            cc = cc + num

        d = 0
        e = 0
        # pprint(List1)
        # pprint(List2)
        for num in List1:
            d = d + square(num)
        for num in List2:
            e = e + square(num)

        f = multiplication(int(d), e)
        g = square_root(int(f))
        h = division(int(g), cc)
        # pprint(float(cc))
        # pprint(e)
        # pprint(f)
        # pprint(float(g))
        # pprint(str(round(h,9)))
        nCorrelation = round(h, 9)
        # pprint(nCorrelation)
        return nCorrelation
    except ZeroDivisionError:
        print("Error - Cannot divide by 0")
    except ValueError:
        print("Error - Invalid data inputs")
def variance_pop_proportion(data):
    p = proportion(data)
    s = subtraction(p, 1)
    n = len(data)
    return division(multiplication(p, s), n)
Esempio n. 21
0
 def multiply(self, a, b):
     self.result = multiplication(a, b)
     return self.result
Esempio n. 22
0
 def multiply(self, a, b):
     ##Multiply Function##
     self.result = multiplication(a, b)
     return self.result
Esempio n. 23
0
 def test_multiplication(self):
     self.assertEqual(6, multiplication(2,3))
Esempio n. 24
0
 def margin(data, seed):
     zs = Z_Score.zscore(data, seed)
     sd = StandardDeviation.standard_deviance(data)
     margin = multiplication(zs, sd)
     return margin
Esempio n. 25
0
def v_pop_proportion(lst):
    prob_will = proportion(lst)
    prob_wont = subtraction(prob_will, 1)
    result = multiplication(prob_wont, prob_will)
    vpp = division(result, len(lst))
    return vpp
def var_pop_proportion(data):
    p = proportion(data)
    q = subtraction(1, p)
    n = len(data)
    return division(n, multiplication(p, q))
def confidence_interval_SUB(confidence_interval_SUB_list):
    return subtraction(
        population_mean(confidence_interval_SUB_list),
        (multiplication(zscore(confidence_interval_SUB_list)),
         division(population_standard_deviance(confidence_interval_SUB_list),
                  square_root(num_values))))
Esempio n. 28
0
 def multiply(self, num1, num2):
     self.result = multiplication(num1, num2)
     return self.result
def variance_population_proportion(variance_population_proportion_list):
    return square_root(division(multiplication(subtraction(population_mean(variance_population_proportion_list), 1)), population_mean(variance_population_proportion_list), num_values))