def print_summary(self): """ Print summary statistics describing the fit, the coefficients, and the error bounds. """ # pylint: disable=unnecessary-lambda # Print information about data first justify = string_justify(18) print(self) print("{} = {}".format(justify("event col"), self.event_col)) print("{} = {}".format(justify("number of subjects"), self._n_unique)) print("{} = {}".format(justify("number of periods"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {:.3f}".format(justify("log-likelihood"), self._log_likelihood)) print( "{} = {} UTC".format(justify("time fit was run"), self._time_fit_was_called), end="\n\n" ) print("---") df = self.summary # Significance codes last df[""] = [significance_code(p) for p in df["p"]] print(df.to_string(float_format=lambda f: "{:4.4f}".format(f))) # Significance code explanation print("---") print(significance_codes_as_text(), end="\n\n") print( "Likelihood ratio test = {:.3f} on {} df, p={:.5f}".format( *self._compute_likelihood_ratio_test() ) )
def print_summary(self): """ Print summary statistics describing the fit, the coefficients, and the error bounds. """ # Print information about data first justify = string_justify(18) print(self) print("{} = {}".format(justify('event col'), self.event_col)) print('{} = {}'.format(justify('number of subjects'), self._n_unique)) print('{} = {}'.format(justify('number of periods'), self._n_examples)) print('{} = {}'.format(justify('number of events'), self.event_observed.sum())) print('{} = {:.3f}'.format(justify('log-likelihood'), self._log_likelihood)) print('{} = {} UTC'.format(justify('time fit was run'), self._time_fit_was_called), end='\n\n') print('---') df = self.summary # Significance codes last df[''] = [significance_code(p) for p in df['p']] print(df.to_string(float_format=lambda f: '{:4.4f}'.format(f))) # Significance code explanation print('---') print(significance_codes_as_text(), end='\n\n') print("Likelihood ratio test = {:.3f} on {} df, p={:.5f}".format(*self._compute_likelihood_ratio_test())) return
def print_summary(self, decimals=2, **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 kwargs: print additional metadata in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ justify = string_justify(18) print(self) print("{} = {}".format(justify("number of subjects"), self.durations.shape[0])) print("{} = {}".format(justify("number of events"), np.where(self.event_observed)[0].shape[0])) print("{} = {:.3f}".format(justify("log-likelihood"), self._log_likelihood)) print("{} = {}".format(justify("hypothesis"), "lambda != 1, rho != 1")) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary print(df.to_string(float_format=format_floats(decimals), formatters={"p": format_p_value(decimals)}))
def print_summary(self, decimals=2, **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 kwargs: print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ # Print information about data first justify = string_justify(18) print(self) print("{} = '{}'".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = '{}'".format(justify("weights col"), self.weights_col)) if self.strata: print("{} = {}".format(justify("strata"), self.strata)) if self.penalizer > 0: print("{} = {}".format(justify("penalizer"), self.penalizer)) print("{} = {}".format(justify("number of subjects"), self._n_unique)) print("{} = {}".format(justify("number of periods"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {:.{prec}f}".format(justify("log-likelihood"), self._log_likelihood, prec=decimals)) print("{} = {} UTC".format(justify("time fit was run"), self._time_fit_was_called)) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary # Significance codes last print( df.to_string( float_format=format_floats(decimals), formatters={"p": format_p_value(decimals), "exp(coef)": format_exp_floats(decimals)}, ) ) # Significance code explanation print("---") with np.errstate(invalid="ignore", divide="ignore"): sr = self.log_likelihood_ratio_test() print( "Log-likelihood ratio test = {:.{prec}f} on {} df, -log2(p)={:.{prec}f}".format( sr.test_statistic, sr.degrees_freedom, -np.log2(sr.p_value), prec=decimals ) )
def _stringify_meta_data(self, dictionary): longest_key = max([len(k) for k in dictionary]) justify = string_justify(longest_key) s = "" for k, v in dictionary.items(): s += "{} = {}\n".format(justify(k), v) return s
def print_summary(self, decimals=2, **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 alpha: float or iterable specify confidence intervals to show kwargs: print additional metadata in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ # Print information about data first justify = string_justify(18) print(self) print("{} = '{}'".format(justify("duration col"), self.duration_col)) if self.event_col: print("{} = '{}'".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = '{}'".format(justify("weights col"), self.weights_col)) if self.penalizer > 0: print("{} = {}".format(justify("penalizer"), self.penalizer)) if self.robust: print("{} = {}".format(justify("robust variance"), True)) print("{} = {}".format(justify("number of subjects"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {:.{prec}f}".format(justify("log-likelihood"), self._log_likelihood, prec=decimals)) print("{} = {}".format(justify("time fit was run"), self._time_fit_was_called)) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary # Significance codes as last column print( df.to_string( float_format=format_floats(decimals), formatters={"p": format_p_value(decimals), "exp(coef)": format_exp_floats(decimals)}, ) ) # Significance code explanation print("---") print("Concordance = {:.{prec}f}".format(self.score_, prec=decimals)) print( "Log-likelihood ratio test = {:.{prec}f} on {} df, -log2(p)={:.{prec}f}".format( *self._compute_likelihood_ratio_test(), prec=decimals ) )
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_justify(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)
def print_summary(self, decimals=2, **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 kwargs: print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ # Print information about data first justify = string_justify(18) print(self) print("{} = '{}'".format(justify("duration col"), self.duration_col)) print("{} = '{}'".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = '{}'".format(justify("weights col"), self.weights_col)) if self.coef_penalizer > 0: print("{} = '{}'".format(justify("coef penalizer"), self.coef_penalizer)) if self.smoothing_penalizer > 0: print("{} = '{}'".format(justify("smoothing penalizer"), self.smoothing_penalizer)) print("{} = {}".format(justify("number of subjects"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {}".format(justify("time fit was run"), self._time_fit_was_called)) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary print( df.to_string( float_format=format_floats(decimals), formatters={ "p": format_p_value(decimals), "exp(coef)": format_exp_floats(decimals) }, )) # Significance code explanation print("---") print("Concordance = {:.{prec}f}".format(self.score_, prec=decimals))
def print_summary(self, decimals=2, **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 kwargs: print additional metadata in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ # Print information about data first justify = string_justify(18) print(self) print("{} = '{}'".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = '{}'".format(justify("weights col"), self.weights_col)) if self.strata: print("{} = {}".format(justify("strata"), self.strata)) print("{} = {}".format(justify("number of subjects"), self._n_unique)) print("{} = {}".format(justify("number of periods"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {:.{prec}f}".format(justify("log-likelihood"), self._log_likelihood, prec=decimals)) print("{} = {} UTC".format(justify("time fit was run"), self._time_fit_was_called)) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary # Significance codes last df[""] = [significance_code(p) for p in df["p"]] print( df.to_string(float_format=format_floats(decimals), formatters={"p": format_p_value(decimals)})) # Significance code explanation print("---") print(significance_codes_as_text(), end="\n\n") print( "Likelihood ratio test = {:.{prec}f} on {} df, log(p)={:.{prec}f}". format(*self._compute_likelihood_ratio_test(), prec=decimals))
def print_summary(self, decimals=2, **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 kwargs: print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ # Print information about data first justify = string_justify(18) print(self) print("{} = '{}'".format(justify("duration col"), self.duration_col)) print("{} = '{}'".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = '{}'".format(justify("weights col"), self.weights_col)) if self.coef_penalizer > 0: print("{} = '{}'".format(justify("coef penalizer"), self.coef_penalizer)) if self.smoothing_penalizer > 0: print("{} = '{}'".format(justify("smoothing penalizer"), self.smoothing_penalizer)) print("{} = {}".format(justify("number of subjects"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {}".format(justify("time fit was run"), self._time_fit_was_called)) for k, v in kwargs.items(): print("{} = {}\n".format(justify(k), v)) print(end="\n") print("---") df = self.summary print( df.to_string( float_format=format_floats(decimals), formatters={"p": format_p_value(decimals), "exp(coef)": format_exp_floats(decimals)}, ) ) # Significance code explanation print("---") print("Concordance = {:.{prec}f}".format(self.score_, prec=decimals))
def print_summary(self): """ Print summary statistics describing the fit. """ justify = string_justify(18) print(self) print('{} = {}'.format(justify('number of subjects'), self.durations.shape[0])) print('{} = {}'.format(justify('number of events'), np.where(self.event_observed)[0].shape[0])) print('{} = {:.3f}'.format(justify('log-likelihood'), self._log_likelihood), end='\n\n') df = self.summary df[''] = [significance_code(p) for p in df['p']] print(df.to_string(float_format=lambda f: '{:4.4f}'.format(f))) print('---') print(significance_codes_as_text(), end='\n\n') return
def print_summary(self): """ Print summary statistics describing the fit. """ # Print information about data first justify = string_justify(18) print(self) print("{} = {}".format(justify('duration col'), self.duration_col)) print("{} = {}".format(justify('event col'), self.event_col)) if self.weights_col: print("{} = {}".format(justify('weights col'), self.weights_col)) if self.cluster_col: print("{} = {}".format(justify('cluster col'), self.cluster_col)) if self.robust or self.cluster_col: print("{} = {}".format(justify('robust variance'), True)) if self.strata: print('{} = {}'.format(justify('strata'), self.strata)) print('{} = {}'.format(justify('number of subjects'), self._n_examples)) print('{} = {}'.format(justify('number of events'), self.event_observed.sum())) print('{} = {:.3f}'.format(justify('log-likelihood'), self._log_likelihood)) print('{} = {}'.format(justify("time fit was run"), self._time_fit_was_called), end='\n\n') print('---') df = self.summary # Significance codes last df[''] = [significance_code(p) for p in df['p']] print(df.to_string(float_format=lambda f: '{:4.4f}'.format(f))) # Significance code explanation print('---') print(significance_codes_as_text(), end='\n\n') print("Concordance = {:.3f}".format(self.score_)) print("Likelihood ratio test = {:.3f} on {} df, p={:.5f}".format( *self._compute_likelihood_ratio_test())) return
def print_summary(self): """ Print summary statistics describing the fit. """ # pylint: disable=unnecessary-lambda # Print information about data first justify = string_justify(18) print(self) print("{} = {}".format(justify("duration col"), self.duration_col)) print("{} = {}".format(justify("event col"), self.event_col)) if self.weights_col: print("{} = {}".format(justify("weights col"), self.weights_col)) if self.cluster_col: print("{} = {}".format(justify("cluster col"), self.cluster_col)) if self.robust or self.cluster_col: print("{} = {}".format(justify("robust variance"), True)) if self.strata: print("{} = {}".format(justify("strata"), self.strata)) print("{} = {}".format(justify("number of subjects"), self._n_examples)) print("{} = {}".format(justify("number of events"), self.event_observed.sum())) print("{} = {:.3f}".format(justify("log-likelihood"), self._log_likelihood)) print("{} = {}".format(justify("time fit was run"), self._time_fit_was_called), end="\n\n") print("---") df = self.summary # Significance codes last df[""] = [significance_code(p) for p in df["p"]] print(df.to_string(float_format=lambda f: "{:4.4f}".format(f))) # Significance code explanation print("---") print(significance_codes_as_text(), end="\n\n") print("Concordance = {:.3f}".format(self.score_)) print("Likelihood ratio test = {:.3f} on {} df, p={:.5f}".format( *self._compute_likelihood_ratio_test()))
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_justify(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)
def print_summary(self): """ Print summary statistics describing the fit. """ # pylint: disable=unnecessary-lambda justify = string_justify(18) print(self) print("{} = {}".format(justify("number of subjects"), self.durations.shape[0])) print("{} = {}".format(justify("number of events"), np.where(self.event_observed)[0].shape[0])) print("{} = {:.3f}".format(justify("log-likelihood"), self._log_likelihood), end="\n\n") df = self.summary df[""] = [significance_code(p) for p in df["p"]] print(df.to_string(float_format=lambda f: "{:4.4f}".format(f))) print("---") print(significance_codes_as_text(), end="\n\n")
def print_summary(self, decimals=2, style=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} kwargs: print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ justify = string_justify(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 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), ]) p = Printer(headers, self, justify, decimals, kwargs) p.print(style=style)
def print_summary(self, decimals=2, **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 kwargs: print additional meta data in the output (useful to provide model names, dataset names, etc.) when comparing multiple outputs. """ justify = string_justify(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.cluster_col: headers.append(("cluster col", "'%s'" % self.cluster_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), ]) p = Printer(headers, self, justify, decimals, kwargs) p.print()