Skip to content

Instantly share code, notes, and snippets.

@gbushnell
Created October 1, 2020 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbushnell/67c99620f09019cb18c6a4624fe35664 to your computer and use it in GitHub Desktop.
Save gbushnell/67c99620f09019cb18c6a4624fe35664 to your computer and use it in GitHub Desktop.
# Calculate Confidence Intervals for probability matrix
def calc_confidence_interval(alpha):
alpha_stat = stats.norm.ppf(1 - (1 - alpha) / 2)
for d_i in range(expected_prob_matrix.shape[0]):
for n_i in range(expected_prob_matrix.shape[1]):
prop_exp = expected_prob_matrix[d_i, n_i]
half_length = alpha_stat * (prop_exp * (1 - prop_exp) / data_cols_length[n_i]) ** .5 + (
1 / (2 * data_cols_length[n_i]))
u_bound = prop_exp + half_length
l_bound = prop_exp - half_length
h_length_matrix[d_i, n_i] = half_length
u_bound_matrix[d_i, n_i] = u_bound
l_bound_matrix[d_i, n_i] = max(l_bound, 0)
calc_confidence_interval(alpha_level)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment