#NEWLINE# def calc_confidence_interval_table( n , confidence_interval_level = 0.95 , percentiles = range ( 8 , 97 , 2 ) ) : #NEWLINE# #INDENT# percentile_lower_bound = [ None for i in range ( n ) ] #NEWLINE# percentile_upper_bound = [ None for i in range ( n ) ] #NEWLINE# limits = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# range_sum = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for percentile in percentiles : #NEWLINE# #INDENT# order_statistic_probs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for i in range ( 0 , ( n + 1 ) ) : #NEWLINE# #INDENT# order_statistic_probs [ i ] = probPercentile ( ( percentile * 0.01 ) , n , i ) #NEWLINE# #UNINDENT# max_order_statistic_prob = [ ( i , order_statistic_probs [ i ] ) for i in order_statistic_probs if ( order_statistic_probs [ i ] == max ( order_statistic_probs . values ( ) ) ) ] #NEWLINE# lower_max_order_statistic_prob = min ( [ i for ( i , val ) in max_order_statistic_prob ] ) #NEWLINE# upper_max_order_statistic_prob = max ( [ i for ( i , val ) in max_order_statistic_prob ] ) #NEWLINE# for i in range ( 0 , ( n / 2 ) ) : #NEWLINE# #INDENT# myrange = range ( max ( 0 , ( lower_max_order_statistic_prob - i ) ) , min ( len ( order_statistic_probs ) , ( ( 1 + upper_max_order_statistic_prob ) + i ) ) ) #NEWLINE# range_sum [ percentile ] = sum ( [ order_statistic_probs [ j ] for j in myrange ] ) #NEWLINE# if ( range_sum [ percentile ] >= confidence_interval_level ) : #NEWLINE# #INDENT# limits [ percentile ] = ( min ( myrange ) , ( 1 + max ( myrange ) ) ) #NEWLINE# for i in myrange [ 0 : ( - 1 ) ] : #NEWLINE# #INDENT# percentile_upper_bound [ i ] = percentile #NEWLINE# if ( not percentile_lower_bound [ i ] ) : #NEWLINE# #INDENT# percentile_lower_bound [ i ] = percentile #NEWLINE# #UNINDENT# #UNINDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return { #NEWLINE# #INDENT# 'range_sum' : range_sum , #NEWLINE# 'limits' : limits , #NEWLINE# 'lookup_table' : zip ( percentile_lower_bound , percentile_upper_bound ) , #NEWLINE# #UNINDENT# }