コード例 #1
0
def proportion(size, corr):
    if corr is None:
        corr = 10

    result = division(corr, size)

    return roundOff(result)
コード例 #2
0
def division(a, b):
    error = exceptions(a, b)
    if error:
        result = float(b) / float(a)
        return roundOff(result)
    else:
        return 0
コード例 #3
0
 def test_divide_method_calculatorCSV(self):
     test_data = CsvReader('Data/Division.csv').data
     for row in test_data:
         result = roundOff((row['Result']))
         self.assertEqual(
             self.calculator.divide(row['Value 1'], row['Value 2']), result)
         self.assertEqual(self.calculator.result, result)
コード例 #4
0
def addition(a, b):
    error = exceptions(a, b)
    if error:
        result = float(a) + float(b)
        return roundOff(result)
    else:
        return 0
コード例 #5
0
def subtraction(a, b):
    error = exceptions(a, b)
    if error:
        result = float(b) - float(a)
        return roundOff(result)
    else:
        return 0
コード例 #6
0
 def test_add_method_calculatorCSV(self):
     test_data = CsvReader('Data/Addition.csv').data
     for row in test_data:
         result = roundOff(float(row['Result']))
         self.assertEqual(
             self.calculator.add(row['Value 1'], row['Value 2']), result)
         self.assertEqual(self.calculator.result, result)
コード例 #7
0
def square(a):
    error = exception(a)
    if error:
        result = float(a) * float(a)
        return roundOff(result)
    else:
        return 0
コード例 #8
0
 def test_sqrt_method_calculatorCSV(self):
     test_data = CsvReader('Data/Square Root.csv').data
     for row in test_data:
         result = roundOff(float(row['Result']))
         self.assertAlmostEqual(self.calculator.squareroot(row['Value 1']),
                                result)
         self.assertAlmostEqual(self.calculator.result, result)
コード例 #9
0
def multiplication(a, b):
    error = exceptions(a, b)
    if error:
        result = float(a) * float(b)
        return roundOff(result)
    else:
        return 0
コード例 #10
0
    def test_method_zscore(self):
        mean = self.row_data.columns['mean'][0]
        sd = self.row_data.columns['sd'][0]
        zscore = roundOff(self.row_data.columns['zscore'][0])

        # zscore = roundOff(float(row['zscore']))
        self.assertEqual(self.stats.zscore(self.stats_row[0], mean, sd), zscore)
        self.assertEqual(self.stats.result, zscore)
        self.assertNotEqual(self.stats.result, square(zscore))
コード例 #11
0
def confidenceInterval(array, conf):

    n = squareroot(len(array))
    mean = calMean(array)
    sd = stddev(array)
    if conf == 80:
        t = 1.282
    elif conf == 85:
        t = 1.440
    elif conf == 90:
        t = 1.645
    elif conf == 95:
        t = 1.960
    else:  # 99.5 default confidence percentage
        t = 2.807

    ciLower = subtraction(multiplication(division(n, sd), t), mean)
    ciUpper = addition(mean, multiplication(division(n, sd), t))
    return roundOff(ciLower), roundOff(ciUpper)
コード例 #12
0
def calMedian(a):
    length = len(a)
    half = int(division(2, length))

    for val in a:
        exception(val)

    if length % 2 == 0:
        median = division(2, addition(a[half - 1], a[half]))
    else:
        median = a[half]

    return roundOff(median)
コード例 #13
0
def calMode(array):
    length = len(array)
    count = defaultdict(list)
    mode = 0
    for i in range(length):
        count[array[i]].append(1)

    k = count[0]
    for i in count:
        if count[i] > k:
            k = count[i]
            mode = i
    # TODO: Add condition to check if multiple value has highest numbers
    return roundOff(mode)
def calcPCC(xArray, yArray):
    xMean = calMean(xArray)
    yMean = calMean(yArray)
    length = len(xArray)
    xSd = stddev(xArray)
    ySd = stddev(xArray)
    total = 0

    for i in range(0, length):
        total = addition(
            total,
            multiplication(division(xSd, subtraction(xMean, xArray[i])),
                           division(ySd, subtraction(yMean, yArray[i]))))
        # total = subtraction(xMean, yArray[i])
    res = division(length, total)

    return roundOff(res)
コード例 #15
0
def varProportion(array, corr):
    n = len(array)
    prop = proportion(n, corr)
    res = division(n, multiplication(prop, subtraction(1, prop)))

    return roundOff(res)
コード例 #16
0
 def test_add_method_calculator(self):
     result = roundOff(4)
     self.assertEqual(self.calculator.add(2, 2), result)
     self.assertEqual(self.calculator.result, result)
コード例 #17
0
def varpp(a):
    val = stddev(a)
    result = square(val)
    return roundOff(result)
コード例 #18
0
 def test_subtract_method_calculator(self):
     result = roundOff(0)
     self.assertEqual(self.calculator.subtract(2, 2), result)
     self.assertEqual(self.calculator.result, result)
コード例 #19
0
 def test_method_variance_pop_prop(self):
     corr = 10
     result = roundOff(0.1)
     self.assertEqual(self.stats.varProp(self.stats_row, corr), result)
     self.assertNotEqual(self.stats.result, square(result))
コード例 #20
0
 def test_method_confidence_interval(self):
     conf = 95
     result = [roundOff(4710.97), roundOff(6901.43)]
     self.assertEqual(self.stats.confInt(self.stats_row, conf), (result[0], result[1]))
コード例 #21
0
 def test_method_pcc(self):
     cc = roundOff(float(self.row_data.columns['CC'][0]))
     self.assertEqual(self.stats.pcc(self.stats_row, self.yStats_row), cc)
     self.assertEqual(self.stats.result, cc)
コード例 #22
0
 def test_divide_method_calculator(self):
     result = roundOff(2)
     self.assertEqual(self.calculator.divide(4, 8), result)
     self.assertEqual(self.calculator.result, result)
コード例 #23
0
 def test_method_vpp(self):
     vpp = roundOff(float(self.row_data.columns['vpp'][0]))
     self.assertEqual(self.stats.vpp(self.stats_row), vpp)
     self.assertEqual(self.stats.result, vpp)
     self.assertNotEqual(self.stats.result, square(vpp))
コード例 #24
0
 def test_method_sd(self):
     sd = roundOff(float(self.row_data.columns['sd'][0]))
     self.assertEqual(self.stats.sd(self.stats_row), sd)
     self.assertEqual(self.stats.result, sd)
コード例 #25
0
 def test_square_method_calculator(self):
     result = roundOff(16)
     self.assertEqual(self.calculator.square(4), result)
     self.assertEqual(self.calculator.result, result)
コード例 #26
0
def zscore(a, mean, sd):
    # TODO: Make an array loop to verify all values
    return roundOff(division(sd, subtraction(mean, a)))
コード例 #27
0
 def test_sqrt_method_calculator(self):
     result = roundOff(2)
     self.assertEqual(self.calculator.squareroot(4), result)
     self.assertEqual(self.calculator.result, result)
コード例 #28
0
 def test_method_median(self):
     median = roundOff(float(self.row_data.columns['median'][0]))
     self.assertEqual(self.stats.median(self.stats_row), median)
     self.assertEqual(self.stats.result, median)
     self.assertNotEqual(self.stats.result, square(median))
コード例 #29
0
 def test_method_mode(self):
     mode = roundOff(float(self.row_data.columns['mode'][0]))
     self.assertEqual(self.stats.mode(self.stats_row), mode)
     self.assertEqual(self.stats.result, mode)
     self.assertNotEqual(self.stats.result, square(mode))