Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add option to select stats to display under coefs in summary2.summary_col #9261

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

EBoisseauSierra
Copy link

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

This PR introduces a new optional argument to statsmodels.iolib.summary2.summary_col, which allows choosing which stat to display under the coefficients:

  def summary_col(
      results,
      float_format: str ='%.4f',
      model_names=(),
      stars=False,
      info_dict=None,
      regressor_order=(),
      drop_omitted=False,
      include_r2=True,
+     coef_stats: str="std_error",
  ):

Example:

  • std_error (default, current behaviour):
=======================
                  y    
-----------------------
const          0.5000  
               (0.6708)
x1             0.6000  
               (0.2449)
R-squared      0.3000  
R-squared Adj. 0.2500  
=======================
Standard errors in
parentheses.
  • t_stat:

=======================
                  y    
-----------------------
const          0.5000  
               (0.7454)
x1             0.6000  
               (2.4495)
R-squared      0.3000  
R-squared Adj. 0.2500  
=======================
t-statistics in
parentheses.
  • z_stat:
=======================
                  y    
-----------------------
const          0.5000  
               (0.7454)
x1             0.6000  
               (2.4495)
R-squared      0.3000  
R-squared Adj. 0.2500  
=======================
z-statistics in
parentheses.
  • "" or None:
=====================
                 y   
---------------------
const          0.5000
x1             0.6000
R-squared      0.3000
R-squared Adj. 0.2500
=====================
  • "foobar":
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ebosi/perso/statsmodels/statsmodels/iolib/summary2.py", line 543, in summary_col
    raise ValueError("coef_stats must be one of 'std_error', 't_stat', "
ValueError: coef_stats must be one of 'std_error', 't_stat', 'z_stat', or an empty string. Got 'foobar' instead.

Signed-off-by: Étienne Boisseau-Sierra <[email protected]>
Signed-off-by: Étienne Boisseau-Sierra <[email protected]>
@josef-pkt
Copy link
Member

is this still WIP?

I'm now working on merging the other two summary_col PRs
This and the other 2 PRs have merge conflicts, that I want to work through in sequence. I would like to add this PR last if it is finished.

@josef-pkt
Copy link
Member

typing makes signatures really difficult to read

@EBoisseauSierra
Copy link
Author

is this still WIP?

I was waiting for both other PRs to be merged to rebase this branch and ensure it's green before requesting a formal review because I'm aware there are conflicts.

typing makes signatures really difficult to read

YMMV. I felt better trying to increase type hints "coverage" within the codebase — which I find very helpful when contributing. But I don't mind dropping them; let me know what you want.

@josef-pkt
Copy link
Member

I don't like type hints in code that I regularly maintain and enhance. Type hints are much too distracting, annoying to read and slows down skimming code.
I don't mind type hints in code that I have to look at only every few years, summary is one of those.

Are you using type hints as part of the code documentation or for type checking in editors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants