def popcorrelation(data1, data2): covxy = 0 n = 0 xmean = Mean.mean(data1) ymean = Mean.mean(data2) xstd = StandardDeviation.stardardDev(data1) ystd = StandardDeviation.stardardDev(data2) if (len(data1) == len(data2)): for x, y in zip(data1, data2): n += 1 covxy += abs((int(x - xmean) * int(y - ymean)) / n) return covxy / (xstd * ystd)
def samplecorrelation(data1, data2): numerator = 0 n = 0 meanofx = Mean.mean(data1) meanofy = Mean.mean(data2) stdevx = StandardDeviation.stardardDev(data1) stdevy = StandardDeviation.stardardDev(data2) if len(data1) == len(data2): for x, y in zip(data1, data2): n += 1 numerator += abs( (int(x - meanofx) * int(y - meanofy)) / (n - 1)) return numerator / (stdevx * stdevy)
def setUp(self): self.sample = Sample() self.list1 = Randm.randList(1, 100, 30, 99) self.size = len(self.list1) self.standarddev = StandardDeviation.stardardDev(self.list1) self.merror = 3 self.mean = Mean.mean(self.list1)
def confInterval(data, cval=0.95): mean = Mean.mean(data) standardDev = StandardDeviation.stardardDev(data) n = len(data) zscr = ZScore.zscore(cval) num = round(zscr * (standardDev / nthroot.root(2, n)), 2) return round((mean - num), 2), round(mean), round((mean + num), 2)
def meanDeviation(data): m = Mean.mean(data) total = 0 l = len(data) for i in data: total = total + absolute(i - m) return (total / l)
def confInterval(data): zvalue = ZScore.zscore(data) stdDev = StandardDeviation.stardardDev(data) mean = Mean.mean(data) n = len(data) num = round(zvalue * (stdDev / nthroot.root(2, n)), 2) return round((mean - num), 2), round(mean), round((mean + num), 2)
def zscore(data): newData = [] mean = Mean.mean(data) stdDev = StandardDeviation.stardardDev(data) for i in data: newData.append((i - mean)/stdDev) return newData
def stardardDev(data): n = len(data) mn = Mean.mean(data) newlist = [] for i in data: newlist.append(Exponentiation.power(i - mn, 2)) total = Addition.sumList(newlist) return nthroot.root(2, Division.divide(total, n))
def meanDev(data): newlist = [] meanOfData = Mean.mean(data) for i in data: newlist.append(abs(i - meanOfData)) total = Addition.sumList(newlist) return Division.divide(total, len(data))
def confidenceIntervalPop(conf, data): lngth = len(data) mean = Mean.mean(data) std_err = sem(data) high = std_err * t.ppf((1 + conf) / 2, lngth - 1) start = mean - high end = mean + high return start, end
def test_StatisticFunctions_Mean(self): self.assertEqual(38.95, Mean.mean(self.testData))
def meanDeviation(data): return Mean.mean(absolute(asarray(data) - Mean.mean(data)))
def mean(self, data): self.result = Mean.mean(data) return self.result
def variance(data): return Mean.mean(absolute(asarray(data) - Mean.mean(data))**2)
def skewness(data): mean = Mean.mean(data) median = Median.med(data) stdDev = StandardDeviation.stardardDev(data) return (3 * (mean - median)) / stdDev