Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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