Skip to content

Commit

Permalink
Merge pull request statsmodels#8004 from bashtage/doc-slim
Browse files Browse the repository at this point in the history
MAINT: Add slim to summary docstring
(cherry picked from commit 66ecf2e)

# Conflicts:
#	statsmodels/regression/tests/test_regression.py
  • Loading branch information
bashtage authored and Kevin Sheppard committed Feb 1, 2022
1 parent 7513828 commit ecb53e4
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 @@ -2639,7 +2637,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 @@ -2654,8 +2659,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 @@ -2671,7 +2679,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 @@ -2721,8 +2731,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 @@ -2790,8 +2799,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 @@ -1598,3 +1598,15 @@ def test_summary_no_constant():
y = rs.standard_normal(100)
summary = OLS(y, x).fit().summary()
assert "R² is computed " in summary.as_text()


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 ecb53e4

Please sign in to comment.