def confidenceInterval(array, ci): df = len(array) - 1 alpha = 1 - ci tval = stats.t.ppf(1 - alpha, df) stdev = Stats.standardDeviation(array) se = stdev / math.pow(len(array), .5) numerate = se * tval mean = Stats.mean(array) return [mean - numerate, mean + numerate]
def known_pop_sample(data): zs = Stats.zscore(data) me = Sampling.marginError(data) sd = Stats.standardDeviation(data) value = (zs * sd) / me popSample = value**0.5 return popSample
def unknown_pop_sample(data, percent): zs = Stats.zscore(data) me = Sampling.marginError(data) p = percent q = 1 - p val = zs / me samplePop = val**0.5 * p * q return samplePop
def Standarddeviation(self, a): self.Result = Stats.standardDeviation(a) return self.Result
def Variance(self, a): self.Result = Stats.variance(a) return self.Result
def test_Stats_Median(self): self.assertEqual(9.0, Stats.median(self.testData)) self.assertEqual(9, Stats.median(self.testDataTwo))
def ZScore(self, a): self.Result = Stats.zscore(a) return self.Result
def SampleCorrelation(self, a): self.Result = Stats.correlationS(a) return self.Result
def test_Stats_Correlation_Sample(self): arr = [self.testData, self.testDataTwo] self.assertEqual(0.9729647047577678, Stats.correlationS(arr))
def test_Stats_Skew(self): self.assertEqual(0.003103728079018511, Stats.skew(self.testData))
def test_Stats_Quartiles(self): result = Stats.quartiles(self.testData) self.assertEqual(4, result[0]) self.assertEqual(9.0, result[1]) self.assertEqual(15, result[2])
def test_Stats_Standard_Deviation(self): self.assertEqual(6.109737219299115, Stats.standardDeviation(self.testData))
def test_Stats_Variance(self): self.assertEqual(37.328888888888876, Stats.variance(self.testData))
def test_Stats_Mode(self): self.assertEqual(1, Stats.mode(self.testData))
def Quartiles(self, a): self.Result = Stats.quartiles(a) return self.Result
def Skewness(self, a): self.Result = Stats.skew(a) return self.Result
def test_Stats_Correlation_Population(self): arr = [self.testData, self.testDataTwo] self.assertEqual(1.0065152118183804, Stats.correlationP(arr))
def PopulationCorrelation(self, a): self.Result = Stats.correlationP(a) return self.Result
def test_Stats_ZScore(self): self.assertEqual(-0.6983388177791585, Stats.zscore(self.testData)[0])
def MeanAbsoluteDeviation(self, a): self.Result = Stats.meanDeviation(a) return self.Result
def test_Stats_Mean_Deviation(self): self.assertEqual(5.484444444444445, Stats.meanDeviation(self.testData))
def marginError(data): zs = Stats.zscore(data) sd = Stats.standardDeviation(data) margin = zs * sd return margin
def Median(self, a): self.Result = Stats.median(a) return self.Result
def Mode(self, a): self.Result = Stats.mode(a) return self.Result
def test_Stats_Mean(self): self.assertEqual(9.266666666666667, Stats.mean(self.testData))