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))
示例#2
0
 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 print_intervals(name, mean_std_min_max):
    beta_par = Fit.Beta.fit_mm(mean=mean_std_min_max[0],
                               st_dev=mean_std_min_max[1],
                               minimum=mean_std_min_max[2],
                               maximum=mean_std_min_max[3])
    # print(beta_par)
    l = scs.beta.ppf(q=0.025,
                     a=beta_par['a'],
                     b=beta_par['b'],
                     loc=beta_par['loc'],
                     scale=beta_par['scale'])
    u = scs.beta.ppf(q=0.975,
                     a=beta_par['a'],
                     b=beta_par['b'],
                     loc=beta_par['loc'],
                     scale=beta_par['scale'])

    print(name, F.format_interval([l, u], deci=2))
示例#4
0
    def get_formatted_interval(self, interval_type='c',
                               alpha=0.05, deci=None, sig_digits=None, form=None, multiplier=1):
        """
        :param interval_type: (string) 'c' for t-based confidence interval,
                                       'cb' for bootstrap confidence interval, and
                                       'p' for percentile interval
        :param alpha: significance level
        :param deci: digits to round the numbers to
        :param sig_digits: number of significant digits
        :param form: ',' to format as number, '%' to format as percentage, and '$' to format as currency
        :param multiplier: to multiply the estimate and the interval by the provided value
        :return: (string) interval formatted as specified
        """

        interval = self.get_interval(interval_type=interval_type, alpha=alpha, multiplier=multiplier)

        return F.format_interval(interval=interval,
                                 deci=deci,
                                 sig_digits=sig_digits,
                                 format=form)
示例#5
0
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)