示例#1
0
    def _stringify_meta_data(self, dictionary):
        longest_key = max([len(k) for k in dictionary])
        justify = string_rjustify(longest_key)
        s = ""
        for k, v in dictionary.items():
            s += "{} = {}\n".format(justify(k), v)

        return s
    def print_summary(self, decimals=2, style=None, columns=None, **kwargs):
        """
        Print summary statistics describing the fit, the coefficients, and the error bounds.

        Parameters
        -----------
        decimals: int, optional (default=2)
            specify the number of decimal places to show
        style: string
            {html, ascii, latex}
        columns:
            only display a subset of ``summary`` columns. Default all.
        kwargs:
            print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing
            multiple outputs.

        """
        justify = string_rjustify(18)

        headers = []

        if self.event_col:
            headers.append(("event col", "'%s'" % self.event_col))
        if self.weights_col:
            headers.append(("weights col", "'%s'" % self.weights_col))
        if isinstance(self.penalizer, np.ndarray) or self.penalizer > 0:
            headers.append(("penalizer", self.penalizer))
        if self.strata:
            headers.append(("strata", self.strata))

        headers.extend([
            ("number of subjects", self._n_unique),
            ("number of periods", self._n_examples),
            ("number of events", self.event_observed.sum()),
            ("partial log-likelihood",
             "{:.{prec}f}".format(self.log_likelihood_, prec=decimals)),
            ("time fit was run", self._time_fit_was_called),
        ])

        sr = self.log_likelihood_ratio_test()
        footers = []
        footers.extend([
            ("Partial AIC", "{:.{prec}f}".format(self.AIC_partial_,
                                                 prec=decimals)),
            (
                "log-likelihood ratio test",
                "{:.{prec}f} on {} df".format(sr.test_statistic,
                                              sr.degrees_freedom,
                                              prec=decimals),
            ),
            ("-log2(p) of ll-ratio test",
             "{:.{prec}f}".format(-utils.quiet_log2(sr.p_value),
                                  prec=decimals)),
        ])

        p = Printer(self, headers, footers, justify, kwargs, decimals, columns)
        p.print(style=style)
示例#3
0
    def print_summary(self, decimals=2, style=None, columns=None, **kwargs):
        """
        Print summary statistics describing the fit, the coefficients, and the error bounds.

        Parameters
        -----------
        decimals: int, optional (default=2)
            specify the number of decimal places to show
        style: string
            {html, ascii, latex}
        columns:
            only display a subset of ``summary`` columns. Default all.
        kwargs:
            print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing
            multiple outputs.

        """
        justify = string_rjustify(25)

        headers = []
        headers.append(("duration col", "'%s'" % self.duration_col))

        if self.event_col:
            headers.append(("event col", "'%s'" % self.event_col))
        if self.weights_col:
            headers.append(("weights col", "'%s'" % self.weights_col))
        if self.coef_penalizer > 0:
            headers.append(("coef penalizer", self.coef_penalizer))
        if self.smoothing_penalizer > 0:
            headers.append(("smoothing penalizer", self.smoothing_penalizer))

        headers.extend([
            ("number of subjects", self._n_examples),
            ("number of events observed", self.event_observed.sum()),
            ("time fit was run", self._time_fit_was_called),
        ])

        footers = [("Concordance",
                    "{:.{prec}f}".format(self.concordance_index_,
                                         prec=decimals))]
        p = Printer(self, headers, footers, justify, kwargs, decimals, columns)

        p.print(style=style)