Example #1
0
    def summary(self):
        """Summary table of model estimation results"""
        smry = super(PanelEffectsResults, self).summary

        is_invalid = np.isfinite(self.f_pooled.stat)
        f_pool = _str(self.f_pooled.stat) if is_invalid else '--'
        f_pool_pval = pval_format(self.f_pooled.pval) if is_invalid else '--'
        f_pool_name = self.f_pooled.dist_name if is_invalid else '--'

        extra_text = []
        if is_invalid:
            extra_text.append('F-test for Poolability: {0}'.format(f_pool))
            extra_text.append('P-value: {0}'.format(f_pool_pval))
            extra_text.append('Distribution: {0}'.format(f_pool_name))
            extra_text.append('')

        if self.included_effects:
            effects = ', '.join(self.included_effects)
            extra_text.append('Included effects: ' + effects)

        if self.other_info is not None:
            ncol = self.other_info.shape[1]
            extra_text.append('Model includes {0} other effects'.format(ncol))
            for c in self.other_info.T:
                col = self.other_info.T[c]
                extra_text.append('Other Effect {0}:'.format(c))
                stats = 'Avg Obs: {0}, Min Obs: {1}, Max Obs: {2}, Groups: {3}'
                stats = stats.format(_str(col['mean']), _str(col['min']),
                                     _str(col['max']), int(col['total']))
                extra_text.append(stats)

        smry.add_extra_txt(extra_text)

        return smry
Example #2
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """
        stubs_lookup = {
            'rsquared': 'R-squared',
            'partial.rsquared': 'Partial R-squared',
            'shea.rsquared': 'Shea\'s R-squared',
            'f.stat': 'Partial F-statistic',
            'f.pval': 'P-value (Partial F-stat)',
            'f.dist': 'Partial F-stat Distn'
        }
        smry = Summary()
        diagnostics = self.diagnostics
        vals = []
        for c in diagnostics:
            if c != 'f.dist':
                vals.append([_str(v) for v in diagnostics[c]])
            else:
                vals.append([v for v in diagnostics[c]])
        stubs = [stubs_lookup[s] for s in list(diagnostics.columns)]
        header = list(diagnostics.index)

        params = []
        for var in header:
            res = self.individual[var]
            v = c_[res.params.values, res.tstats.values]
            params.append(v.ravel())
        params = array(params)
        params_fmt = [[_str(val) for val in row] for row in params.T]
        for i in range(1, len(params_fmt), 2):
            for j in range(len(params_fmt[i])):
                params_fmt[i][j] = '({0})'.format(params_fmt[i][j])

        params_stub = []
        for var in res.params.index:
            params_stub.extend([var, ''])

        title = 'First Stage Estimation Results'

        vals = table_concat((vals, params_fmt))
        stubs = stub_concat((stubs, params_stub))

        txt_fmt = default_txt_fmt.copy()
        txt_fmt['data_aligns'] = 'r'
        txt_fmt['header_align'] = 'r'
        table = SimpleTable(vals,
                            headers=header,
                            title=title,
                            stubs=stubs,
                            txt_fmt=txt_fmt)
        smry.tables.append(table)
        extra_txt = [
            'T-stats reported in parentheses',
            'T-stats use same covariance type as original model'
        ]
        smry.add_extra_txt(extra_txt)
        return smry
Example #3
0
    def summary(self):
        """Summary table of first-stage estimation results"""
        stubs_lookup = {
            'rsquared': 'R-squared',
            'partial.rsquared': 'Partial R-squared',
            'shea.rsquared': 'Shea\'s R-squared',
            'f.stat': 'F-statistic',
            'f.pval': 'P-value (F-stat)'
        }
        smry = Summary()
        diagnostics = self.diagnostics
        vals = [[_str(v) for v in diagnostics[c]] for c in diagnostics]
        stubs = [stubs_lookup[s] for s in list(diagnostics.columns)]
        header = list(diagnostics.index)

        params = []
        for var in header:
            res = self.individual[var]
            v = c_[res.params.values, res.tstats.values]
            params.append(v.ravel())
        params = array(params)
        if params.ndim == 1:
            params = params[:, None]
        params_fmt = [[_str(val) for val in row] for row in params.T]
        for i in range(1, len(params_fmt), 2):
            for j in range(len(params_fmt[i])):
                params_fmt[i][j] = '({0})'.format(params_fmt[i][j])

        params_stub = []
        for var in res.params.index:
            params_stub.extend([var, ''])

        title = 'First Stage Estimation Results'

        vals = table_concat((vals, params_fmt))
        stubs = stub_concat((stubs, params_stub))

        txt_fmt = default_txt_fmt.copy()
        txt_fmt['data_aligns'] = 'r'
        txt_fmt['header_align'] = 'r'
        table = SimpleTable(vals,
                            headers=header,
                            title=title,
                            stubs=stubs,
                            txt_fmt=txt_fmt)
        smry.tables.append(table)
        extra_txt = [
            'T-stats reported in parentheses',
            'T-stats use same covariance type as original model'
        ]
        smry.add_extra_txt(extra_txt)
        return smry
Example #4
0
    def summary(self):
        """Equation summary"""
        title = self._method + ' Estimation Summary'

        top_left = [('Eq. Label:', self.equation_label),
                    ('Dep. Variable:', self.dependent),
                    ('Estimator:', self._method),
                    ('No. Observations:', self.nobs),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')),

                    ('', '')]

        top_right = [('R-squared:', _str(self.rsquared)),
                     ('Adj. R-squared:', _str(self.rsquared_adj)),
                     ('Cov. Estimator:', self._cov_type),
                     ('F-statistic:', _str(self.f_statistic.stat)),
                     ('P-value (F-stat)', pval_format(self.f_statistic.pval)),
                     ('Distribution:', str(self.f_statistic.dist_name)),
                     ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%10s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)
        smry.tables.append(param_table(self, 'Parameter Estimates', pad_bottom=True))

        return smry
Example #5
0
    def summary(self):
        """Model summary"""
        title = 'System ' + self._method + ' Estimation Summary'

        top_left = [('Estimator:', self._method),
                    ('No. Equations.:', str(len(self.equation_labels))),
                    ('No. Observations:', str(self.resids.shape[0])),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')),
                    ('', ''),
                    ('', '')]

        top_right = [('Overall R-squared:', _str(self.rsquared)),
                     ('Cov. Estimator:', self._cov_type),
                     ('Num. Constraints: ', self._num_constraints),
                     ('', ''),
                     ('', ''),
                     ('', ''),
                     ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%10s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        for eqlabel in self.equation_labels:
            results = self.equations[eqlabel]
            dep_name = results.dependent
            title = 'Equation: {0}, Dependent Variable: {1}'.format(eqlabel, dep_name)
            smry.tables.append(param_table(results, title, pad_bottom=True))

        return smry
Example #6
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        smry = Summary()
        models = list(self._results.keys())
        title = 'Model Comparison'
        stubs = ['Dep. Variable', 'Estimator', 'No. Observations', 'Cov. Est.', 'R-squared',
                 'R-Squared (Within)', 'R-Squared (Between)', 'R-Squared (Overall)',
                 'F-statistic', 'P-value (F-stat)']
        dep_name = {}
        for key in self._results:
            dep_name[key] = self._results[key].model.dependent.vars[0]
        dep_name = Series(dep_name)

        vals = concat([dep_name, self.estimator_method, self.nobs, self.cov_estimator,
                       self.rsquared, self.rsquared_within, self.rsquared_between,
                       self.rsquared_overall, self.f_statistic], 1)
        vals = [[i for i in v] for v in vals.T.values]
        vals[2] = [str(v) for v in vals[2]]
        for i in range(4, len(vals)):
            f = _str
            if i == 9:
                f = pval_format
            vals[i] = [f(v) for v in vals[i]]

        params = self.params
        tstats = self.tstats
        params_fmt = []
        params_stub = []
        for i in range(len(params)):
            params_fmt.append([_str(v) for v in params.values[i]])
            tstats_fmt = []
            for v in tstats.values[i]:
                v_str = _str(v)
                v_str = '({0})'.format(v_str) if v_str.strip() else v_str
                tstats_fmt.append(v_str)
            params_fmt.append(tstats_fmt)
            params_stub.append(params.index[i])
            params_stub.append(' ')

        vals = table_concat((vals, params_fmt))
        stubs = stub_concat((stubs, params_stub))

        all_effects = []
        for key in self._results:
            res = self._results[key]
            effects = getattr(res, 'included_effects', [])
            all_effects.append(effects)

        neffect = max(map(len, all_effects))
        effects = []
        effects_stub = ['Effects']
        for i in range(neffect):
            if i > 0:
                effects_stub.append('')
            row = []
            for j in range(len(self._results)):
                effect = all_effects[j]
                if len(effect) > i:
                    row.append(effect[i])
                else:
                    row.append('')
            effects.append(row)
        if effects:
            vals = table_concat((vals, effects))
            stubs = stub_concat((stubs, effects_stub))

        txt_fmt = default_txt_fmt.copy()
        txt_fmt['data_aligns'] = 'r'
        txt_fmt['header_align'] = 'r'
        table = SimpleTable(vals, headers=models, title=title, stubs=stubs, txt_fmt=txt_fmt)
        smry.tables.append(table)
        smry.add_extra_txt(['T-stats reported in parentheses'])
        return smry
Example #7
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = self.name + ' Estimation Summary'
        mod = self.model

        top_left = [('Dep. Variable:', mod.dependent.vars[0]),
                    ('Estimator:', self.name),
                    ('No. Observations:', self.nobs),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')),
                    ('Cov. Estimator:', self._cov_type),
                    ('', ''),
                    ('Entities:', str(int(self.entity_info['total']))),
                    ('Avg Obs:', _str(self.entity_info['mean'])),
                    ('Min Obs:', _str(self.entity_info['min'])),
                    ('Max Obs:', _str(self.entity_info['max'])),
                    ('', ''),
                    ('Time periods:', str(int(self.time_info['total']))),
                    ('Avg Obs:', _str(self.time_info['mean'])),
                    ('Min Obs:', _str(self.time_info['min'])),
                    ('Max Obs:', _str(self.time_info['max'])),
                    ('', '')]

        is_invalid = np.isfinite(self.f_statistic.stat)
        f_stat = _str(self.f_statistic.stat) if is_invalid else '--'
        f_pval = pval_format(self.f_statistic.pval) if is_invalid else '--'
        f_dist = self.f_statistic.dist_name if is_invalid else '--'

        f_robust = _str(self.f_statistic_robust.stat) if is_invalid else '--'
        f_robust_pval = pval_format(self.f_statistic_robust.pval) if is_invalid else '--'
        f_robust_name = self.f_statistic_robust.dist_name if is_invalid else '--'

        top_right = [('R-squared:', _str(self.rsquared)),
                     ('R-squared (Between):', _str(self.rsquared_between)),
                     ('R-squared (Within):', _str(self.rsquared_within)),
                     ('R-squared (Overall):', _str(self.rsquared_overall)),
                     ('Log-likelihood', _str(self._loglik)),
                     ('', ''),
                     ('F-statistic:', f_stat),
                     ('P-value', f_pval),
                     ('Distribution:', f_dist),
                     ('', ''),
                     ('F-statistic (robust):', f_robust),
                     ('P-value', f_robust_pval),
                     ('Distribution:', f_robust_name),
                     ('', ''),
                     ('', ''),
                     ('', ''),
                     ('', ''),
                     ]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%18s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        param_data = np.c_[self.params.values[:, None],
                           self.std_errors.values[:, None],
                           self.tstats.values[:, None],
                           self.pvalues.values[:, None],
                           self.conf_int()]
        data = []
        for row in param_data:
            txt_row = []
            for i, v in enumerate(row):
                f = _str
                if i == 3:
                    f = pval_format
                txt_row.append(f(v))
            data.append(txt_row)
        title = 'Parameter Estimates'
        table_stubs = list(self.params.index)
        header = ['Parameter', 'Std. Err.', 'T-stat', 'P-value', 'Lower CI', 'Upper CI']
        table = SimpleTable(data,
                            stubs=table_stubs,
                            txt_fmt=fmt_params,
                            headers=header,
                            title=title)
        smry.tables.append(table)

        return smry
Example #8
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = self._method + ' Estimation Summary'

        top_left = [('Eq. Label:', self.equation_label),
                    ('Dep. Variable:', self.dependent),
                    ('Estimator:', self._method),
                    ('No. Observations:', self.nobs),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')), ('', '')]

        top_right = [('R-squared:', _str(self.rsquared)),
                     ('Adj. R-squared:', _str(self.rsquared_adj)),
                     ('Cov. Estimator:', self._cov_type),
                     ('F-statistic:', _str(self.f_statistic.stat)),
                     ('P-value (F-stat)', pval_format(self.f_statistic.pval)),
                     ('Distribution:', str(self.f_statistic.dist_name)),
                     ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%10s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)
        smry.tables.append(
            param_table(self, 'Parameter Estimates', pad_bottom=True))

        extra_text = []
        instruments = self._instruments
        if instruments:
            endog = self._endog
            extra_text = []
            extra_text.append('Endogenous: ' + ', '.join(endog))
            extra_text.append('Instruments: ' + ', '.join(instruments))

        extra_text.append('Covariance Estimator:')
        for line in str(self._cov_estimator).split('\n'):
            extra_text.append(line)
        if self._weight_estimator:
            extra_text.append('Weight Estimator:')
            for line in str(self._weight_estimator).split('\n'):
                extra_text.append(line)
        smry.add_extra_txt(extra_text)

        return smry
Example #9
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = 'System ' + self._method + ' Estimation Summary'

        top_left = [('Estimator:', self._method),
                    ('No. Equations.:', str(len(self.equation_labels))),
                    ('No. Observations:', str(self.resids.shape[0])),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')), ('', ''),
                    ('', '')]

        top_right = [('Overall R-squared:', _str(self.rsquared)),
                     ('Cov. Estimator:', self._cov_type),
                     ('Num. Constraints: ', self._num_constraints), ('', ''),
                     ('', ''), ('', ''), ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%10s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        for i, eqlabel in enumerate(self.equation_labels):
            last_row = i == (len(self.equation_labels) - 1)
            results = self.equations[eqlabel]
            dep_name = results.dependent
            title = 'Equation: {0}, Dependent Variable: {1}'.format(
                eqlabel, dep_name)
            pad_bottom = results.instruments is not None and not last_row
            smry.tables.append(
                param_table(results, title, pad_bottom=pad_bottom))
            if results.instruments:
                formatted = format_wide(results.instruments, 80)
                if not last_row:
                    formatted.append([' '])
                smry.tables.append(
                    SimpleTable(formatted, headers=['Instruments']))
        extra_text = ['Covariance Estimator:']
        for line in str(self._cov_estimator).split('\n'):
            extra_text.append(line)
        if self._weight_estimtor:
            extra_text.append('Weight Estimator:')
            for line in str(self._weight_estimtor).split('\n'):
                extra_text.append(line)
        smry.add_extra_txt(extra_text)

        return smry
Example #10
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = self.name + ' Estimation Summary'

        top_left = [('No. Test Portfolios:', len(self._portfolio_names)),
                    ('No. Factors:', len(self._factor_names)),
                    ('No. Observations:', self.nobs),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')),
                    ('Cov. Estimator:', self._cov_type), ('', '')]

        j_stat = _str(self.j_statistic.stat)
        j_pval = pval_format(self.j_statistic.pval)
        j_dist = self.j_statistic.dist_name

        top_right = [('R-squared:', _str(self.rsquared)),
                     ('J-statistic:', j_stat), ('P-value', j_pval),
                     ('Distribution:', j_dist), ('', ''), ('', ''), ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%18s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        rp = np.asarray(self.risk_premia)[:, None]
        se = np.asarray(self.risk_premia_se)[:, None]
        tstats = np.asarray(self.risk_premia / self.risk_premia_se)
        pvalues = 2 - 2 * stats.norm.cdf(np.abs(tstats))
        ci = rp + se * stats.norm.ppf([[0.025, 0.975]])
        param_data = np.c_[rp, se, tstats[:, None], pvalues[:, None], ci]
        data = []
        for row in param_data:
            txt_row = []
            for i, v in enumerate(row):
                f = _str
                if i == 3:
                    f = pval_format
                txt_row.append(f(v))
            data.append(txt_row)
        title = 'Risk Premia Estimates'
        table_stubs = list(self.risk_premia.index)
        header = [
            'Parameter', 'Std. Err.', 'T-stat', 'P-value', 'Lower CI',
            'Upper CI'
        ]
        table = SimpleTable(data,
                            stubs=table_stubs,
                            txt_fmt=fmt_params,
                            headers=header,
                            title=title)
        smry.tables.append(table)
        smry.add_extra_txt([
            'Covariance estimator:',
            str(self._cov_est), 'See full_summary for complete results'
        ])

        return smry
Example #11
0
    def summary(self) -> Summary:
        """
        Model estimation summary.

        Returns
        -------
        Summary
            Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = self._method + " Estimation Summary"

        top_left = [
            ("Eq. Label:", self.equation_label),
            ("Dep. Variable:", self.dependent),
            ("Estimator:", self._method),
            ("No. Observations:", self.nobs),
            ("Date:", self._datetime.strftime("%a, %b %d %Y")),
            ("Time:", self._datetime.strftime("%H:%M:%S")),
            ("", ""),
        ]

        top_right = [
            ("R-squared:", _str(self.rsquared)),
            ("Adj. R-squared:", _str(self.rsquared_adj)),
            ("Cov. Estimator:", self._cov_type),
            ("F-statistic:", _str(self.f_statistic.stat)),
            ("P-value (F-stat)", pval_format(self.f_statistic.pval)),
            ("Distribution:", str(self.f_statistic.dist_name)),
            ("", ""),
        ]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt["data_fmts"][1] = "%10s"

        top_right = [("%-21s" % ("  " + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)
        smry.tables.append(
            param_table(self, "Parameter Estimates", pad_bottom=True))

        extra_text = []
        instruments = self._instruments
        if instruments:
            endog = self._endog
            extra_text = [
                "Endogenous: " + ", ".join(endog),
                "Instruments: " + ", ".join(instruments),
            ]

        extra_text.append("Covariance Estimator:")
        for line in str(self._cov_estimator).split("\n"):
            extra_text.append(line)
        if self._weight_estimator:
            extra_text.append("Weight Estimator:")
            for line in str(self._weight_estimator).split("\n"):
                extra_text.append(line)
        smry.add_extra_txt(extra_text)

        return smry
Example #12
0
    def summary(self) -> Summary:
        """
        Model estimation summary.

        Returns
        -------
        Summary
            Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = "System " + self._method + " Estimation Summary"

        top_left = [
            ("Estimator:", self._method),
            ("No. Equations.:", str(len(self.equation_labels))),
            ("No. Observations:", str(self.resids.shape[0])),
            ("Date:", self._datetime.strftime("%a, %b %d %Y")),
            ("Time:", self._datetime.strftime("%H:%M:%S")),
            ("", ""),
            ("", ""),
        ]

        top_right = [
            ("Overall R-squared:", _str(self.rsquared)),
            ("McElroy's R-squared:", _str(self.system_rsquared.mcelroy)),
            ("Judge's (OLS) R-squared:", _str(self.system_rsquared.judge)),
            ("Berndt's R-squared:", _str(self.system_rsquared.berndt)),
            ("Dhrymes's R-squared:", _str(self.system_rsquared.dhrymes)),
            ("Cov. Estimator:", self._cov_type),
            ("Num. Constraints: ", self._num_constraints),
        ]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt["data_fmts"][1] = "%10s"

        top_right = [("%-21s" % ("  " + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        for i, eqlabel in enumerate(self.equation_labels):
            last_row = i == (len(self.equation_labels) - 1)
            results = self.equations[eqlabel]
            dep_name = results.dependent
            title = "Equation: {0}, Dependent Variable: {1}".format(
                eqlabel, dep_name)
            pad_bottom = results.instruments is not None and not last_row
            smry.tables.append(
                param_table(results, title, pad_bottom=pad_bottom))
            if results.instruments:
                formatted = format_wide(results.instruments, 80)
                if not last_row:
                    formatted.append([" "])
                smry.tables.append(
                    SimpleTable(formatted, headers=["Instruments"]))
        extra_text = ["Covariance Estimator:"]
        for line in str(self._cov_estimator).split("\n"):
            extra_text.append(line)
        if self._weight_estimtor:
            extra_text.append("Weight Estimator:")
            for line in str(self._weight_estimtor).split("\n"):
                extra_text.append(line)
        smry.add_extra_txt(extra_text)

        return smry
Example #13
0
    def summary(self):
        """Summary table of model estimation results"""

        title = self._method + ' Estimation Summary'
        mod = self.model
        top_left = [('Dep. Variable:', mod.dependent.cols[0]),
                    ('Estimator:', self._method),
                    ('No. Observations:', self.nobs),
                    ('Date:', self._datetime.strftime('%a, %b %d %Y')),
                    ('Time:', self._datetime.strftime('%H:%M:%S')),
                    ('Cov. Estimator:', self._cov_type), ('', '')]

        top_right = [('R-squared:', _str(self.rsquared)),
                     ('Adj. R-squared:', _str(self.rsquared_adj)),
                     ('F-statistic:', _str(self.f_statistic.stat)),
                     ('P-value (F-stat)', pval_format(self.f_statistic.pval)),
                     ('Distribution:', str(self.f_statistic.dist_name)),
                     ('', ''), ('', '')]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt['data_fmts'][1] = '%18s'

        top_right = [('%-21s' % ('  ' + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        param_data = c_[self.params.values[:, None],
                        self.std_errors.values[:, None],
                        self.tstats.values[:, None], self.pvalues.values[:,
                                                                         None],
                        self.conf_int()]
        data = []
        for row in param_data:
            txt_row = []
            for i, v in enumerate(row):
                f = _str
                if i == 3:
                    f = pval_format
                txt_row.append(f(v))
            data.append(txt_row)
        title = 'Parameter Estimates'
        table_stubs = list(self.params.index)
        header = [
            'Parameters', 'Std. Err.', 'T-stat', 'P-value', 'Lower CI',
            'Upper CI'
        ]
        table = SimpleTable(data,
                            stubs=table_stubs,
                            txt_fmt=fmt_params,
                            headers=header,
                            title=title)
        smry.tables.append(table)

        instruments = self.model.instruments
        if instruments.shape[1] > 0:
            extra_text = []
            endog = self.model.endog
            extra_text.append('Endogenous: ' + ', '.join(endog.cols))
            extra_text.append('Instruments: ' + ', '.join(instruments.cols))
            cov_descr = str(self._cov_estimator)
            for line in cov_descr.split('\n'):
                extra_text.append(line)
            smry.add_extra_txt(extra_text)

        return smry
Example #14
0
    def summary(self):
        """Summary table of model comparison"""
        smry = Summary()
        models = list(self._results.keys())
        title = 'Model Comparison'
        stubs = [
            'Dep. Variable', 'Estimator', 'No. Observations', 'Cov. Est.',
            'R-squared', 'Adj. R-squared', 'F-statistic', 'P-value (F-stat)'
        ]
        dep_name = {}
        for key in self._results:
            dep_name[key] = self._results[key].model.dependent.cols[0]
        dep_name = Series(dep_name)

        vals = concat([
            dep_name, self.estimator_method, self.nobs, self.cov_estimator,
            self.rsquared, self.rsquared_adj, self.f_statistic
        ], 1)
        vals = [[i for i in v] for v in vals.T.values]
        vals[2] = [str(v) for v in vals[2]]
        for i in range(4, len(vals)):
            vals[i] = [_str(v) for v in vals[i]]

        params = self.params
        tstats = self.tstats
        params_fmt = []
        params_stub = []
        for i in range(len(params)):
            params_fmt.append([_str(v) for v in params.values[i]])
            tstats_fmt = []
            for v in tstats.values[i]:
                v_str = _str(v)
                v_str = '({0})'.format(v_str) if v_str.strip() else v_str
                tstats_fmt.append(v_str)
            params_fmt.append(tstats_fmt)
            params_stub.append(params.index[i])
            params_stub.append(' ')

        vals = table_concat((vals, params_fmt))
        stubs = stub_concat((stubs, params_stub))

        all_instr = []
        for key in self._results:
            res = self._results[key]
            all_instr.append(res.model.instruments.cols)
        ninstr = max(map(lambda l: len(l), all_instr))
        instruments = []
        instrument_stub = ['Instruments']
        for i in range(ninstr):
            if i > 0:
                instrument_stub.append('')
            row = []
            for j in range(len(self._results)):
                instr = all_instr[j]
                if len(instr) > i:
                    row.append(instr[i])
                else:
                    row.append('')
            instruments.append(row)
        if instruments:
            vals = table_concat((vals, instruments))
            stubs = stub_concat((stubs, instrument_stub))

        txt_fmt = default_txt_fmt.copy()
        txt_fmt['data_aligns'] = 'r'
        txt_fmt['header_align'] = 'r'
        table = SimpleTable(vals,
                            headers=models,
                            title=title,
                            stubs=stubs,
                            txt_fmt=txt_fmt)
        smry.tables.append(table)
        smry.add_extra_txt(['T-stats reported in parentheses'])
        return smry
Example #15
0
    def summary(self) -> Summary:
        """
        Model estimation summary.

        Returns
        -------
        Summary
            Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """

        title = self.name + " Estimation Summary"

        top_left = [
            ("No. Test Portfolios:", len(self._portfolio_names)),
            ("No. Factors:", len(self._factor_names)),
            ("No. Observations:", self.nobs),
            ("Date:", self._datetime.strftime("%a, %b %d %Y")),
            ("Time:", self._datetime.strftime("%H:%M:%S")),
            ("Cov. Estimator:", self._cov_type),
            ("", ""),
        ]

        j_stat = _str(self.j_statistic.stat)
        j_pval = pval_format(self.j_statistic.pval)
        j_dist = self.j_statistic.dist_name

        top_right = [
            ("R-squared:", _str(self.rsquared)),
            ("J-statistic:", j_stat),
            ("P-value", j_pval),
            ("Distribution:", j_dist),
            ("", ""),
            ("", ""),
            ("", ""),
        ]

        stubs = []
        vals = []
        for stub, val in top_left:
            stubs.append(stub)
            vals.append([val])
        table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)

        # create summary table instance
        smry = Summary()
        # Top Table
        # Parameter table
        fmt = fmt_2cols
        fmt["data_fmts"][1] = "%18s"

        top_right = [("%-21s" % ("  " + k), v) for k, v in top_right]
        stubs = []
        vals = []
        for stub, val in top_right:
            stubs.append(stub)
            vals.append([val])
        table.extend_right(SimpleTable(vals, stubs=stubs))
        smry.tables.append(table)

        rp = np.asarray(self.risk_premia)[:, None]
        se = np.asarray(self.risk_premia_se)[:, None]
        tstats = np.asarray(self.risk_premia / self.risk_premia_se)
        pvalues = 2 - 2 * stats.norm.cdf(np.abs(tstats))
        ci = rp + se * stats.norm.ppf([[0.025, 0.975]])
        param_data = np.c_[rp, se, tstats[:, None], pvalues[:, None], ci]
        data = []
        for row in param_data:
            txt_row = []
            for i, v in enumerate(row):
                f = _str
                if i == 3:
                    f = pval_format
                txt_row.append(f(v))
            data.append(txt_row)
        title = "Risk Premia Estimates"
        table_stubs = list(self.risk_premia.index)
        header = ["Parameter", "Std. Err.", "T-stat", "P-value", "Lower CI", "Upper CI"]
        table = SimpleTable(
            data, stubs=table_stubs, txt_fmt=fmt_params, headers=header, title=title
        )
        smry.tables.append(table)
        smry.add_extra_txt(
            [
                "Covariance estimator:",
                str(self._cov_est),
                "See full_summary for complete results",
            ]
        )

        return smry
Example #16
0
    def summary(self):
        """:obj:`statsmodels.iolib.summary.Summary` : Summary table of model estimation results

        Supports export to csv, html and latex  using the methods ``summary.as_csv()``,
        ``summary.as_html()`` and ``summary.as_latex()``.
        """
        smry = Summary()
        models = list(self._results.keys())
        title = 'Model Comparison'
        stubs = ['Dep. Variable', 'Estimator', 'No. Observations', 'Cov. Est.', 'R-squared',
                 'Adj. R-squared', 'F-statistic', 'P-value (F-stat)']
        dep_name = OrderedDict()
        for key in self._results:
            dep_name[key] = self._results[key].model.dependent.cols[0]
        dep_name = Series(dep_name)

        vals = concat([dep_name, self.estimator_method, self.nobs, self.cov_estimator,
                       self.rsquared, self.rsquared_adj, self.f_statistic], 1)
        vals = [[i for i in v] for v in vals.T.values]
        vals[2] = [str(v) for v in vals[2]]
        for i in range(4, len(vals)):
            vals[i] = [_str(v) for v in vals[i]]

        params = self.params
        precision = getattr(self, self._precision)
        params_fmt = []
        params_stub = []
        for i in range(len(params)):
            params_fmt.append([_str(v) for v in params.values[i]])
            precision_fmt = []
            for v in precision.values[i]:
                v_str = _str(v)
                v_str = '({0})'.format(v_str) if v_str.strip() else v_str
                precision_fmt.append(v_str)
            params_fmt.append(precision_fmt)
            params_stub.append(params.index[i])
            params_stub.append(' ')

        vals = table_concat((vals, params_fmt))
        stubs = stub_concat((stubs, params_stub))

        all_instr = []
        for key in self._results:
            res = self._results[key]
            all_instr.append(res.model.instruments.cols)
        ninstr = max(map(len, all_instr))
        instruments = []
        instrument_stub = ['Instruments']
        for i in range(ninstr):
            if i > 0:
                instrument_stub.append('')
            row = []
            for j in range(len(self._results)):
                instr = all_instr[j]
                if len(instr) > i:
                    row.append(instr[i])
                else:
                    row.append('')
            instruments.append(row)
        if instruments:
            vals = table_concat((vals, instruments))
            stubs = stub_concat((stubs, instrument_stub))

        txt_fmt = default_txt_fmt.copy()
        txt_fmt['data_aligns'] = 'r'
        txt_fmt['header_align'] = 'r'
        table = SimpleTable(vals, headers=models, title=title, stubs=stubs, txt_fmt=txt_fmt)
        smry.tables.append(table)
        prec_type = self._PRECISION_TYPES[self._precision]
        smry.add_extra_txt(['{0} reported in parentheses'.format(prec_type)])
        return smry