예제 #1
0
def variance(data):
    varMean = mean(data)

    listDiffs = []
    for eachNum in data:
        eachDiff = subtraction(eachNum, varMean)
        listDiffs.append(eachDiff)

    listSquares = []
    for eachDiff in listDiffs:
        eachSquare = squaring(eachDiff)
        listSquares.append(eachSquare)

    return mean(listSquares)
예제 #2
0
def variance(num):
    Mean_var = mean(num)

    Man = []
    for n in num:
        Variables = subtraction(n, Mean_var)
        Man.append(Variables)

    Squares = []
    for Variables in Man:
        Square_var = square(Variables)
        Squares.append(Square_var)

    return mean(Squares)
예제 #3
0
def median(num):
    num.sort()
    length = len(num)
    result = None
    index1 = int(division(2, length))
    if length % 2 == 0:
        index2 = int(subtraction(index1, 1))
        value1 = num[index1]
        value2 = num[index2]
        result = mean([value1, value2])
    else:
        result = num[index1]
    return float(result)
예제 #4
0
def zscore(data):
    dataMean = mean(data)
    stanDev = standard_deviation(data)

    listMinuses = []
    for eachRaw in data:
        meanMinusRaw = subtraction(dataMean, eachRaw)
        listMinuses.append(meanMinusRaw)

    listZScores = []
    for eachMinus in listMinuses:
        eachZ = division(stanDev, eachMinus)
        listZScores.append(eachZ)

    return listZScores
예제 #5
0
def zscore(num):
    Mean_var = mean(num)
    standardDev_var = standardDev(num)

    negative = []
    for Raw_var in num:
        meanRaw = subtraction(Mean_var, Raw_var)
        negative.append(meanRaw)

    ZScore_var = []
    for neg in negative:
        z = division(standardDev_var, neg)
        ZScore_var.append(z)

    return ZScore_var
예제 #6
0
def confidence_interval(sample):
    # finding sample standard deviation

    old_sample_size = len(sample)
    new_sample_size = subtraction(1, old_sample_size)
    sample_mean = mean(sample)

    subtract_mean_result = []
    for item in sample:
        result = subtraction(sample_mean, item)
        subtract_mean_result.append(result)

    squared_list = []
    for num in subtract_mean_result:
        squared_result = squaring(num)
        squared_list.append(squared_result)

    squared_list_total = 0
    for num in squared_list:
        squared_list_total += num

    sample_variance = division(new_sample_size, squared_list_total)
    sample_deviation = squarerooting(sample_variance)

    # finding confidence interval

    confidence_level = .95
    t_distribution = 2.262
    # taken from t_distribution chart https://www.statisticshowto.com/probability-and-statistics/confidence-interval/#CISample

    confidence_minus_one = subtraction(confidence_level, 1)
    new_confidence = division(2, confidence_minus_one)

    squareroot_of_sample = squarerooting(old_sample_size)
    CI = division(squareroot_of_sample, sample_deviation)
    interval = multiplication(CI, t_distribution)

    lower_end = subtraction(interval, sample_mean)
    upper_end = addition(interval, sample_mean)
    width = subtraction(lower_end, upper_end)

    return [lower_end, upper_end, width]
 def mean(self, data):
     self.result = mean(data)
     return self.result