def pprint_matrix(values, rlabels, clabels, col_space=None): buf = StringIO() T, K = len(rlabels), len(clabels) if col_space is None: min_space = 10 col_space = [max(len(str(c)) + 2, min_space) for c in clabels] else: col_space = (col_space,) * K row_space = max([len(str(x)) for x in rlabels]) + 2 head = _pfixed('', row_space) for j, h in enumerate(clabels): head += _pfixed(h, col_space[j]) buf.write(head + '\n') for i, rlab in enumerate(rlabels): line = ('%s' % rlab).ljust(row_space) for j in range(K): line += _pfixed(values[i,j], col_space[j]) buf.write(line + '\n') return buf.getvalue()
def print_ic_table(ics, selected_orders): """ For VAR order selection """ # Can factor this out into a utility method if so desired cols = sorted(ics) data = mat([["%#10.4g" % v for v in ics[c]] for c in cols], dtype=object).T # start minimums for i, col in enumerate(cols): idx = int(selected_orders[col]), i data[idx] = data[idx] + '*' # data[idx] = data[idx][:-1] + '*' # super hack, ugh fmt = dict(_default_table_fmt, data_fmts=("%s", ) * len(cols)) buf = StringIO() table = SimpleTable(data, cols, lrange(len(data)), title='VAR Order Selection', txt_fmt=fmt) buf.write(str(table) + '\n') buf.write('* Minimum' + '\n') print(buf.getvalue())
def pprint_matrix(values, rlabels, clabels, col_space=None): buf = StringIO() T, K = len(rlabels), len(clabels) if col_space is None: min_space = 10 col_space = [max(len(str(c)) + 2, min_space) for c in clabels] else: col_space = (col_space, ) * K row_space = max([len(str(x)) for x in rlabels]) + 2 head = _pfixed('', row_space) for j, h in enumerate(clabels): head += _pfixed(h, col_space[j]) buf.write(head + '\n') for i, rlab in enumerate(rlabels): line = ('%s' % rlab).ljust(row_space) for j in range(K): line += _pfixed(values[i, j], col_space[j]) buf.write(line + '\n') return buf.getvalue()
def print_ic_table(ics, selected_orders): """ For VAR order selection """ # Can factor this out into a utility method if so desired cols = sorted(ics) data = mat([["%#10.4g" % v for v in ics[c]] for c in cols], dtype=object).T # start minimums for i, col in enumerate(cols): idx = int(selected_orders[col]), i data[idx] = data[idx] + '*' # data[idx] = data[idx][:-1] + '*' # super hack, ugh fmt = dict(_default_table_fmt, data_fmts=("%s",) * len(cols)) buf = StringIO() table = SimpleTable(data, cols, lrange(len(data)), title='VAR Order Selection', txt_fmt=fmt) buf.write(str(table) + '\n') buf.write('* Minimum' + '\n') print(buf.getvalue())
def _resid_info(self): buf = StringIO() names = self.model.names buf.write("Correlation matrix of residuals" + '\n') buf.write(pprint_matrix(self.model.resid_corr, names, names) + '\n') return buf.getvalue()
def summary(self): buf = StringIO() rng = lrange(self.periods) for i in range(self.neqs): ppm = output.pprint_matrix(self.decomp[i], rng, self.names) buf.write('FEVD for %s\n' % self.names[i]) buf.write(ppm + '\n') print(buf.getvalue())
def hypothesis_test_table(results, title, null_hyp): fmt = dict(_default_table_fmt, data_fmts=["%#15.6F","%#15.6F","%#15.3F", "%s"]) buf = StringIO() table = SimpleTable([[results['statistic'], results['crit_value'], results['pvalue'], str(results['df'])]], ['Test statistic', 'Critical Value', 'p-value', 'df'], [''], title=None, txt_fmt=fmt) buf.write(title + '\n') buf.write(str(table) + '\n') buf.write(null_hyp + '\n') buf.write("Conclusion: %s H_0" % results['conclusion']) buf.write(" at %.2f%% significance level" % (results['signif'] * 100)) return buf.getvalue()
def hypothesis_test_table(results, title, null_hyp): fmt = dict(_default_table_fmt, data_fmts=["%#15.6F", "%#15.6F", "%#15.3F", "%s"]) buf = StringIO() table = SimpleTable([[ results['statistic'], results['crit_value'], results['pvalue'], str(results['df']) ]], ['Test statistic', 'Critical Value', 'p-value', 'df'], [''], title=None, txt_fmt=fmt) buf.write(title + '\n') buf.write(str(table) + '\n') buf.write(null_hyp + '\n') buf.write("Conclusion: %s H_0" % results['conclusion']) buf.write(" at %.2f%% significance level" % (results['signif'] * 100)) return buf.getvalue()
def _coef_table(self): model = self.model k = model.neqs Xnames = self.model.exog_names data = lzip(model.params.T.ravel(), model.stderr.T.ravel(), model.tvalues.T.ravel(), model.pvalues.T.ravel()) header = ('coefficient','std. error','t-stat','prob') buf = StringIO() dim = k * model.k_ar + model.k_trend for i in range(k): section = "Results for equation %s" % model.names[i] buf.write(section + '\n') #print >> buf, section table = SimpleTable(data[dim * i : dim * (i + 1)], header, Xnames, title=None, txt_fmt = self.default_fmt) buf.write(str(table) + '\n') if i < k - 1: buf.write('\n') return buf.getvalue()
def _coef_table(self): model = self.model k = model.neqs Xnames = self.model.exog_names data = lzip(model.params.T.ravel(), model.stderr.T.ravel(), model.tvalues.T.ravel(), model.pvalues.T.ravel()) header = ('coefficient', 'std. error', 't-stat', 'prob') buf = StringIO() dim = k * model.k_ar + model.k_trend for i in range(k): section = "Results for equation %s" % model.names[i] buf.write(section + '\n') #print >> buf, section table = SimpleTable(data[dim * i:dim * (i + 1)], header, Xnames, title=None, txt_fmt=self.default_fmt) buf.write(str(table) + '\n') if i < k - 1: buf.write('\n') return buf.getvalue()
def get_ic_table(ics, selected_orders): ''' 该方法将滞后阶数结果转换为表格化的分析结果 :param ics: 滞后阶数结果 :param selected_orders: 最大滞后阶数 :return: 返回表格化的滞后阶数分析结果 ''' _default_table_fmt = dict(empty_cell='', colsep=' ', row_pre='', row_post='', table_dec_above='=', table_dec_below='=', header_dec_below='-', header_fmt='%s', stub_fmt='%s', title_align='c', header_align='r', data_aligns='r', stubs_align='l', fmt='txt') cols = sorted(ics) data = np.array([["%#10.4g" % v for v in ics[c]] for c in cols], dtype=object).T for i, col in enumerate(cols): idx = int(selected_orders[col]), i data[idx] = data[idx] + '*' fmt = dict(_default_table_fmt, data_fmts=("%s", ) * len(cols)) buf = StringIO() table = SimpleTable(data, cols, lrange(len(data)), title='VAR Order Selection', txt_fmt=fmt) buf.write(str(table) + '\n') buf.write('* Minimum' + '\n') return buf.getvalue()
def make(self, endog_names=None, exog_names=None): """ Summary of VAR model """ buf = StringIO() buf.write(self._header_table() + '\n') buf.write(self._stats_table() + '\n') buf.write(self._coef_table() + '\n') buf.write(self._resid_info() + '\n') return buf.getvalue()