def cochrans(conf, prop): z_critical = z_critical = scipy.stats.norm.ppf(1 - (1 - conf) / 2) z_critical_squared = squaring(z_critical) e = (1-conf) e_squared = squaring(e) cochrans_n = ceil((z_critical_squared * prop * (1-prop)) / e_squared) return cochrans_n
def variance(num): try: pop_mean = populationmean(num) num_values = len(num) x = 0 for i in num: x = x + squaring(i - pop_mean) return round(division(x, num_values), 3) except ValueError: print("Error with data")
def known_pop_sample(data, seed): z_s = Z_Score.zscore(data, seed) m_e = MarginError.margin(data, seed) s_d = StandardDeviation.standard_deviance(data) value = (z_s * s_d) / m_e popSample = squaring(value) return popSample
def unknown_pop_sample(data, seed, percent): z_s = Z_Score.zscore(data, seed) m_e = MarginError.margin(data, seed) p = percent q = subtraction(1, p) val = division(z_s, m_e) samplePop = squaring(val) * p * q return samplePop
def variance(a): try: a_mean = mean(a) n = len(a) x = 0 for i in a: x = x + squaring(i - a_mean) return division(x, n) except ZeroDivisionError: print("Error: Can't Divide by 0") except ValueError: print("Error: Check your data inputs")
def samplevariance(num): try: pop_mean = populationmean(num) num_values = len(num) x = 0 for i in num: x = x + squaring(i - pop_mean) return round(division(x, num_values), 7) except ZeroDivisionError: print("Error: Can't Divide by 0") except ValueError: print("Error: Check your data inputs")
def findsamplesize(conf, width): z_critical = z_critical = scipy.stats.norm.ppf(1 - (1 - conf) / 2) z_critical_squared = squarerooting(z_critical) moe = width / 2 p_hat = .5 q_hat = 1 - p_hat p_times_q = p_hat * q_hat z_div_moe = z_critical / moe z_div_moe_squared = squaring(z_div_moe) n = ceil(p_times_q * z_div_moe_squared) return n
def square(self, a): self.result = squaring(a) return self.result