Skip to content

Instantly share code, notes, and snippets.

@grahamharrison68
Created March 28, 2021 07:47
Show Gist options
  • Save grahamharrison68/0f90421ac2896ffcdd258dd95dcc7051 to your computer and use it in GitHub Desktop.
Save grahamharrison68/0f90421ac2896ffcdd258dd95dcc7051 to your computer and use it in GitHub Desktop.
def normal_distribution_ci(confidence, x_bar, sigma, n):
z_score = stats.norm.interval(confidence)[1]
sigma_over_root_n = sigma / np.sqrt(n)
ci = [x_bar - z_score * sigma_over_root_n, x_bar + z_score * sigma_over_root_n]
return ci
def binomial_distribution_ci(confidence, p_hat, n):
z_score = stats.norm.interval(confidence)[1]
rhs = z_score * np.sqrt(p_hat*(1-p_hat))/n
ci = [p_hat - rhs, p_hat + rhs]
return ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment