def samplestddev(a): try: variance = samplevariance(a) return round(squarerooting(variance), 5) except ZeroDivisionError: print("Error: Can't Divide by 0") except ValueError: print("Error: Check your data inputs")
def stddev(num): try: variance_float = variance(num) return round(squarerooting(variance_float), 5) except ZeroDivisionError: print("Error: Can't Divide by 0") except ValueError: print("Error: Check your data inputs")
def marginoferror(a, conf): n = len(a) z_critical = scipy.stats.norm.ppf(1 - (1 - conf) / 2) sample_stdev = samplestddev(a) se = sample_stdev/squarerooting(n) margin_of_error = z_critical * se return margin_of_error
def confidence_interval_top(num): try: num_values = len(num) z = 1.96 sd = stddev(num) avg = populationmean(num) return round(avg + (z * sd / squarerooting(num_values)), 5) 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 squareroot(self, a): self.result = squarerooting(a) return self.result
def stddev(num): variance_num = variance(num) return round(squarerooting(variance_num), 4)
def confidence_low(num): values = len(num) z = 1.96 stdev1 = stddev(num) avg = populationmean(num) return (avg - (z * stdev1)) / (squarerooting(values))