Skip to content

Commit

Permalink
MAINT: Add slim to summary docstring
Browse files Browse the repository at this point in the history
Add optional parameter slim to docstring of summary
  • Loading branch information
bashtage committed Jan 10, 2022
1 parent 1991c1d commit 17ae496
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
41 changes: 28 additions & 13 deletions statsmodels/regression/linear_model.py
Expand Up @@ -30,11 +30,12 @@
W. Green. "Econometric Analysis," 5th ed., Pearson, 2003.
"""

from __future__ import annotations

from statsmodels.compat.pandas import Appender
from statsmodels.compat.python import lrange, lzip

from typing import Sequence
import warnings

import numpy as np
Expand All @@ -47,12 +48,9 @@
# need import in module instead of lazily to copy `__doc__`
from statsmodels.regression._prediction import PredictionResults
from statsmodels.tools.decorators import cache_readonly, cache_writable
from statsmodels.tools.sm_exceptions import (
InvalidTestWarning,
ValueWarning,
)
from statsmodels.tools.sm_exceptions import InvalidTestWarning, ValueWarning
from statsmodels.tools.tools import pinv_extended
from statsmodels.tools.validation import string_like
from statsmodels.tools.validation import bool_like, float_like, string_like

from . import _prediction as pred

Expand Down Expand Up @@ -2642,7 +2640,14 @@ def get_prediction(self, exog=None, transform=True, weights=None,
self, exog=exog, transform=transform, weights=weights,
row_labels=row_labels, **kwargs)

def summary(self, yname=None, xname=None, title=None, alpha=.05, slim=False):
def summary(
self,
yname: str | None = None,
xname: Sequence[str] | None = None,
title: str | None = None,
alpha: float = 0.05,
slim: bool = False,
):
"""
Summarize the Regression Results.
Expand All @@ -2657,8 +2662,11 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05, slim=False):
title : str, optional
Title for the top table. If not None, then this replaces the
default title.
alpha : float
alpha : float, optional
The significance level for the confidence intervals.
slim : bool, optional
Flag indicating to produce reduced set or diagnostic information.
Default is False.
Returns
-------
Expand All @@ -2674,7 +2682,9 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05, slim=False):
durbin_watson,
jarque_bera,
omni_normtest,
)
)
alpha = float_like(alpha, "alpha", optional=False)
slim = bool_like(slim, "slim", optional=False, strict=True)

jb, jbpv, skew, kurtosis = jarque_bera(self.wresid)
omni, omnipv = omni_normtest(self.wresid)
Expand Down Expand Up @@ -2724,8 +2734,7 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05, slim=False):
slimlist = ['Dep. Variable:', 'Model:', 'No. Observations:',
'Covariance Type:', 'R-squared:', 'Adj. R-squared:',
'F-statistic:', 'Prob (F-statistic):']
diagn_left = []
diagn_right = []
diagn_left = diagn_right = []
top_left = [elem for elem in top_left if elem[0] in slimlist]
top_right = [elem for elem in top_right if elem[0] in slimlist]
else:
Expand Down Expand Up @@ -2793,8 +2802,14 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05, slim=False):

return smry

def summary2(self, yname=None, xname=None, title=None, alpha=.05,
float_format="%.4f"):
def summary2(
self,
yname: str | None = None,
xname: Sequence[str] | None = None,
title: str | None = None,
alpha: float = 0.05,
float_format: str = "%.4f",
):
"""
Experimental summary function to summarize the regression results.
Expand Down
12 changes: 12 additions & 0 deletions statsmodels/regression/tests/test_regression.py
Expand Up @@ -1608,3 +1608,15 @@ def test_condition_number(reset_randomstate):
res = OLS(y, x).fit()
assert_allclose(res.condition_number, np.sqrt(np.linalg.cond(x.T @ x)))
assert_allclose(res.condition_number, np.linalg.cond(x))


def test_slim_summary(reset_randomstate):
y = np.random.standard_normal(100)
x = np.random.standard_normal((100, 1))
x = x + np.random.standard_normal((100, 5))
res = OLS(y, x).fit()
summ = res.summary()
summ2 = res.summary()
slim_summ = res.summary(slim=True)
assert str(summ) == str(summ2)
assert str(slim_summ) != str(summ)

0 comments on commit 17ae496

Please sign in to comment.