Skip to content

ENH: Functions for summarizing multiple model fitting results. - #8328

Open
toshiakiasakura wants to merge 3 commits into
statsmodels:mainfrom
toshiakiasakura:summary_multi
Open

toshiakiasakura wants to merge 3 commits into
statsmodels:mainfrom
toshiakiasakura:summary_multi

Conversation

@toshiakiasakura

@toshiakiasakura toshiakiasakura commented Jun 23, 2022 •

Copy link
Copy Markdown
Contributor
  • closes (None)
  • tests (not tested)
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Although there is a question about how to handle multiple summaries with summary_col.
Python: Do not show dummies in statsmodels summary

However, I thought more featured functions to achieve easy functions of handling with multiple fitting results were needed, and I tried to implement simple one with just horizontal concatenations, and one version which lets a mosaic variable to control layout of outputs.

See the link below for practical usage.
https://github.com/toshiakiasakura/statsmodels/blob/summary_multi/examples/notebooks/summary_multi_usage.ipynb

If there is a further suggestion, improvement or need to open a issue, please tell me.

@pep8speaks

pep8speaks commented Jun 23, 2022 •

Copy link
Copy Markdown

Hello @toshiakiasakura! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-06-29 11:01:43 UTC

@josef-pkt

Copy link
Copy Markdown
Member

@toshiakiasakura
Thanks for the PR

I might not get around looking at this very soon.
I'm setting up a new notebook with dev environment and I will soon go on vacation and travelling.
(I'm trying to get Window 11 to behave like my old Windows 7 or 8)

@bashtage bashtage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed. Most importantly need tests that will visit all branches.

Comment thread statsmodels/iolib/summary_multi.py Outdated

Returns
-------
pd.DataFrame

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just DataFrame

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in feaf2e9

Comment thread statsmodels/iolib/summary_multi.py Resolved
Comment thread statsmodels/iolib/summary_multi.py Resolved
Comment thread statsmodels/iolib/summary_multi.py Resolved
Dictionary for replacing index names.
rows : array_like
Row names for multi index.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example here

Example
-------
>>> from statsmodels.datasets import ???
>>> # more here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A See Also would be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added example, but shoud I write a link to the notebook of example of this function?

Comment thread statsmodels/iolib/summary_multi.py Resolved
def simple_summary_col(
results, accessor=None, index=None, fill_value=None, rename_index=None,
):
if accessor is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this have a docstring. Should this be private? (leading underscore)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a docstring also to it.

Comment thread statsmodels/iolib/summary_multi.py Resolved
-------
result
The result instance with "params_summary" attribute.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is meant to be public, can you add an example here. Also a See Also section could be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reflected yet.
See the following comment.

@toshiakiasakura

Copy link
Copy Markdown
Contributor Author

Currently, I'm working on your code reviews, and I happened to remember to ask you how to add attributes...
Whan I run the following code, I obtain the result as below.

import statsmodels.api as sm
import statsmodels.formula.api as smf
df = sm.datasets.anes96.load_pandas().data
res1 = smf.glm(formula="vote ~ logpopul" ,data=df, family = sm.families.Binomial()).fit()
res2 = sm.add_params_summary(res1)
print(res2.params_summary.to_string())
               coef   std err         t         P>|t|    [0.025    0.975]                      str
Intercept -0.073026  0.083061 -0.879178  3.793048e-01 -0.235823  0.089772   -0.073 (-0.236, 0.090)
logpopul  -0.110967  0.021216 -5.230224  1.693043e-07 -0.152550 -0.069383  -0.111 (-0.153, -0.069)

However, when I run dir(res2), .params_summary does not appear.
I want to let .params_summary can be found from dir method.
I can not figure out which should be modified.

@toshiakiasakura

Copy link
Copy Markdown
Contributor Author

I'm sorry to rush you, but what's going on for this pull request?
Are there some problems, or should I improve my pull request?

@josef-pkt

Copy link
Copy Markdown
Member

I just came back from my vacation and travelling. I will try to look at it during the next few days.

API decisions are difficult and I need to try this out to see how it works.

@EwoutH

EwoutH commented Dec 6, 2022

Copy link
Copy Markdown
Contributor

These look like very useful functions, thanks for this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants