def export_to_csv(self, file_name='PartialRank.csv', decimal=3): formatedResults = [['Parameter', 'Coefficient', 'P-Value']] for row in self.results: name = row[0] coef = F.format_number(number=row[1], deci=decimal) p = F.format_number(number=row[2], deci=decimal) formatedResults.append([name, coef, p]) IO.write_csv(file_name=file_name, rows=formatedResults)
def print_results(stat): print(' Average =', Support.format_number(stat.get_mean(), deci=3)) print(' St Dev =', Support.format_number(stat.get_stdev(), deci=3)) print(' Min =', Support.format_number(stat.get_min(), deci=3)) print(' Max =', Support.format_number(stat.get_max(), deci=3)) print(' Median =', Support.format_number(stat.get_percentile(50), deci=3)) print(' 95% Mean Confidence Interval (t-based) =', Support.format_interval(stat.get_t_CI(0.05), 3)) print(' 95% Mean Confidence Interval (bootstrap) =', Support.format_interval(stat.get_bootstrap_CI(0.05, 1000), 3)) print(' 95% Percentile Interval =', Support.format_interval(stat.get_PI(0.05), 3))
def get_summary(self, alpha, digits): """ :param alpha: significance level :param digits: digits to round the numbers to :return: a list ['name', 'mean', 'confidence interval', 'percentile interval', 'st dev', 'min', 'max'] """ return [self.name, F.format_number(self.get_mean(), digits), F.format_interval(self.get_t_CI(alpha), digits), F.format_interval(self.get_PI(alpha), digits), F.format_number(self.get_stdev(), digits), F.format_number(self.get_min(), digits), F.format_number(self.get_max(), digits)]
def export_to_csv(self, corrs='r', file_name='Correlations.csv', decimal=3, delimiter=','): """ formats the correlation coefficients and p-value to the specified decimal point and exports to a csv file :param corrs: (string) or (list of strings) from 'r' for Pearson's, 'rho' for Spearman's rank correlation, 'p' for partial correlation, and 'pr' for partial rank correlation :param file_name: file name :param decimal: decimal points to round the estimates to :param delimiter: to separate by comma, use ',' and by tab, use '\t' """ if not isinstance(corrs, list): corrs = [corrs] # make the header tile_row = ['Parameter'] for corr in corrs: tile_row.append(self._full_name(corr=corr)) tile_row.append('P-value') # add the header formatted_results = [tile_row] # add the names of parameters (first column) for name in self.dicParameterValues: formatted_results.append([name]) # calculate all forms of correlation requested for corr in corrs: results, text = self._get_results_text(corr=corr) i = 1 for par, values in results.items(): coef = F.format_number(number=values[0], deci=decimal) p = F.format_number(number=values[1], deci=decimal) formatted_results[i].extend([coef, p]) i += 1 IO.write_csv(file_name=file_name, rows=formatted_results, delimiter=delimiter)
def print_switch_icu_info(scenarios, scenario_df): names = [s.name for s in scenarios.CEA.strategies] print('Utilization') for name in names: mean_interval = scenario_df.get_mean_interval( scenario_name=name, outcome_name='Utilization (unit of time): Social Distancing') print(' ', name, ':', F.format_number(mean_interval[0], deci=1)) print('# of switches') for name in names: mean_interval = scenario_df.get_mean_interval( scenario_name=name, outcome_name='Number of Switches') print(' ', name, ':', F.format_number(mean_interval[0], deci=1)) print('% served in ICU') for name in names: mean_interval = scenario_df.get_mean_interval( scenario_name=name, outcome_name='Average ratio: % served in ICU') print(' ', name, ':', F.format_number(mean_interval[0], deci=1, format='%'))
def format_x_axis(ax, min_x, max_x, delta_x, buffer=0, form=None, deci=None): # get x ticks xs = ax.get_xticks() if min_x is None: min_x = xs[0] if max_x is None: max_x = xs[-1] if delta_x is not None: xs = calculate_ticks(min_x, max_x, delta_x) # format x-axis ax.set_xticks(xs) if deci is not None: ax.set_xticklabels( [F.format_number(x, deci=deci, format=form) for x in xs]) ax.set_xlim([min_x - buffer, max_x + buffer])
import SimPy.FormatFunctions as Format print("\nFormatting estimates:") print(Format.format_number(12345.678,deci=1)) print(Format.format_number(12345.678, deci=1, format=Format.FormatNumber.NUMBER)) print(Format.format_number(12345.678, deci=1, format=Format.FormatNumber.CURRENCY)) print(Format.format_number(0.12345, deci=1, format=Format.FormatNumber.PERCENTAGE)) print("\nFormatting intervals:") print(Format.format_interval([12345.678, 98765.432],deci=1)) print(Format.format_interval([12345.678, 98765.432], deci=1, format=Format.FormatNumber.NUMBER)) print(Format.format_interval([12345.678, 98765.432], deci=1, format=Format.FormatNumber.CURRENCY)) print(Format.format_interval([0.12345, 0.98765], deci=1, format=Format.FormatNumber.PERCENTAGE)) print("\nFormatting estimates and intervals:") print(Format.format_estimate_interval( estimate=5555.55, interval=[12345.678, 98765.432],deci=1)) print(Format.format_estimate_interval( estimate=5555.55, interval=[12345.678, 98765.432], deci=1, format=Format.FormatNumber.NUMBER)) print(Format.format_estimate_interval( estimate=5555.55, interval=[12345.678, 98765.432], deci=1, format=Format.FormatNumber.CURRENCY)) print(Format.format_estimate_interval( estimate=0.5555, interval=[0.12345, 0.98765], deci=1, format=Format.FormatNumber.PERCENTAGE))
def calculate_means_and_intervals(self, poster_file='ParameterEstimates.csv', significance_level=0.05, deci=3, ids=None, csv_file_name_prior=None): """ calculate the mean and credible intervals of parameters specified by ids :param poster_file: csv file where the posterior ranges should be stored :param significance_level: :param deci: :param ids: :param csv_file_name_prior: (string) filename where parameter prior ranges are located :return: """ # read prior distributions priors = None if csv_file_name_prior is not None: priors = IO.read_csv_rows(file_name=csv_file_name_prior, if_ignore_first_row=True, delimiter=',', if_convert_float=True) results = [] # list of parameter estimates and credible intervals par_id = 0 for key, value in self.dictOfParams.items(): # skip these columns if key in ['Simulation Replication', 'Random Seed']: continue # if estimates and credible intervals should be calculated for this parameter if_record = False if ids is None: if_record = True elif par_id in ids: if_record = True # record the calculated estimate and credible interval if if_record: if priors is None: decimal = deci form = '' multip = 1 else: decimal = priors[par_id][Column.DECI.value] decimal = 0 if decimal is None else decimal form = priors[par_id][Column.FORMAT.value] multip = priors[par_id][Column.MULTIPLIER.value] if multip is None: data = value else: multip = float(multip) data = [multip * x for x in value] sum_stat = Stat.SummaryStat(name=key, data=data) mean_text = Format.format_number(number=sum_stat.get_mean(), deci=decimal, format=form) PI_text = Format.format_interval( interval=sum_stat.get_PI(significance_level), deci=decimal, format=form) results.append([par_id, key, mean_text, PI_text]) # next parameter par_id += 1 # write parameter estimates and credible intervals IO.write_csv(rows=results, file_name=poster_file)