Skip to content

Instantly share code, notes, and snippets.

View grahamharrison68's full-sized avatar

Graham Harrison grahamharrison68

  • Lincoln College
View GitHub Profile
df_binom_ci['pop_min'] = df_binom_ci.apply(lambda row: binomial_distribution_ci_pop_min(row['confidence'], row['p_hat'], row['n']), axis=1)
df_binom_ci['pop_max'] = df_binom_ci.apply(lambda row: binomial_distribution_ci_pop_max(row['confidence'], row['p_hat'], row['n']), axis=1)
df_binom_ci['confidence_interval'] = df_binom_ci.apply(lambda row: binomial_distribution_ci_text(row['confidence'], row['p_hat'], row['n']), axis=1)
df_binom_ci
df_binom_ci = pd.read_csv("data/binomial_ci_batch.csv")
df_binom_ci
df_normal_ci['pop_min'] = df_normal_ci.apply(lambda row: normal_distribution_ci_pop_min(row['confidence'], row['x_bar'], row['sigma'], row['n']), axis=1)
df_normal_ci['pop_max'] = df_normal_ci.apply(lambda row: normal_distribution_ci_pop_max(row['confidence'], row['x_bar'], row['sigma'], row['n']), axis=1)
df_normal_ci['confidence_interval'] = df_normal_ci.apply(lambda row: normal_distribution_ci_text(row['confidence'], row['x_bar'], row['sigma'], row['n']), axis=1)
df_normal_ci
df_normal_ci = pd.read_csv("data/normal_ci_batch.csv")
df_normal_ci
def normal_distribution_ci_pop_min(confidence, x_bar, sigma, n):
return normal_distribution_ci(confidence, x_bar, sigma, n)[0]
def normal_distribution_ci_pop_max(confidence, x_bar, sigma, n):
return normal_distribution_ci(confidence, x_bar, sigma, n)[1]
def normal_distribution_ci_text(confidence, x_bar, sigma, n):
ci = normal_distribution_ci(confidence, x_bar, sigma, n)
return f"The population mean lies between {ci[0]:.2f} and {ci[1]:.2f} with {confidence:.0%} confidence"
print("Binomial Distribution Confidence Interval Calculator")
@interact_manual(confidence=(0.5, 0.99,0.01), p_hat=(0.0,1.0,0.01), n=n_binomial_input)
def confidence_interval_binomial(confidence=0.95, p_hat=0.78, n=32):
ci = binomial_distribution_ci(confidence, p_hat, n)
print(f"The population mean lies between {ci[0]:.1%} and {ci[1]:.1%} with {confidence:.0%} confidence")
print("Normal Distribution Confidence Interval Calculator")
@interact_manual(confidence=(0.5, 0.99,0.01), x_bar=x_bar_input, sigma=sigma_input, n=n_normal_input)
def confidence_interval_normal(confidence=0.95, x_bar=1000, sigma=1000, n=1000):
ci = normal_distribution_ci(confidence, x_bar, sigma, n)
print(f"The population mean lies between {ci[0]:.2f} and {ci[1]:.2f} with {confidence:.0%} confidence")
x_bar_input = widgets.FloatText(value=75.7, min=0, max=100000, step=0.01, description='x bar:', disabled=False)
sigma_input = widgets.FloatText(value=7.3, min=0, max=100000, step=1, description='sigma:', disabled=False)
n_normal_input = widgets.BoundedIntText(value=30, min=0, max=100000, step=1, description='n:', disabled=False)
n_binomial_input = widgets.BoundedIntText(value=32, min=0, max=100000, step=1, description='n:', disabled=False)
p_hat_test = 0.78
n_test = 32
binomial_distribution_ci(0.95, p_hat_test, n_test)
x_bar_test = 73.0592655207448
sigma_test = 4.500032137012057
n_test = 30
normal_distribution_ci(0.95, x_bar_test, sigma_test, n_test)