Skip to content

DOC: Completed documentation of elements in possible dataFrames from anova_lm - #5233

Closed
jtweeder wants to merge 8 commits into
statsmodels:masterfrom
jtweeder:anova_doc_fix
Closed

jtweeder wants to merge 8 commits into
statsmodels:masterfrom
jtweeder:anova_doc_fix

Conversation

@jtweeder

@jtweeder jtweeder commented Sep 20, 2018 •

Copy link
Copy Markdown
Contributor

Hopefully this is presented in a clean enough way to show what is in the two possible dataFrames that can be returned by anova_lm

Closes #3306

Comment thread statsmodels/stats/anova.py Resolved
Comment thread statsmodels/stats/anova.py Outdated
df : float64
Degress of freedom for model terms.
test statistic : float64
Name dependens on selected test statistic. Returns test statistic

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.

maybe something
The column name is either "F" or "chi2" depending on whether the F-statistic or the chisquare-statistic is used in computing the p-value.
I don't have an example right now to check how chisquare is spelled in the column name.

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.

Possible values for test are as follows:
test : str {"F", "Chisq", "Cp"} or None

Value of the statistic column and Pvalue column return exactly those inputs.

Possible Alternative for docstring:
...
{'F','Chisq','CP'} : float64
....
PR(>{'F','Chisq','CP'}) : float64

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.

I briefly browsed the code and it seems to me only "F" is implemented. (I don't even know what Cp stands for.

I would also prefer if the header/title for the column in the docstring were the same as the pandas column name. But none of the formats look really convincing to me and I don't have much of a preference.

PR(>{'F','Chisq','CP'}) : float64
looks more difficult to interpret than the full list, althout it's shorter, e.g.
PR(>F), P(>Chisq) or P(>CP)

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.

You are correct...You can enter the Chisq or CP but it only returns 0.0 because only the 'F' actually makes anything calculate. (no errors or warnings are returned) Only clue is that P-value and test statistic is 0.0.

CP probably refers to Mallows Cp (never heard of it until today):
http://rafalab.github.io/pages/754/section-09.pdf

I too like the easy to read version. I will add a see notes in the parameters that 'F' is the only implemented test until that functionality can be added later vs removing that parameter from the input.

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.

I think it would be easier for now to just use the "F" version in the description of the DataFrame, which will be much easier.
In this case I don't see an advantage of documenting a return that never shows up in a meaningful way.

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.

Commit c121983 should finish these up

@coveralls

coveralls commented Sep 20, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0008%) to 84.203% when pulling 2e9cf7c on jtweeder:anova_doc_fix into a764908 on statsmodels:master.

@codecov

codecov Bot commented Sep 20, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5233 into master will decrease coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5233      +/-   ##
=========================================
- Coverage    81.7%   81.7%   -0.01%     
=========================================
  Files         569     569              
  Lines       89628   89626       -2     
  Branches    10022   10025       +3     
=========================================
- Hits        73227   73225       -2     
+ Misses      14131   14130       -1     
- Partials     2270    2271       +1
Impacted Files Coverage Δ
statsmodels/stats/anova.py 92% <80%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a764908...1f697ca. Read the comment docs.

Comment thread statsmodels/stats/anova.py Outdated
try:
assert typ in [1,"I"]
except:
if typ not in [1,"1"]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did this change upper-case-i to “1” intentionally? Nitpick: Space after comma pls.

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.

Thank you for that catch...I typoed that "1" in there. Fixed the spacing.

Comment thread statsmodels/stats/anova.py Resolved
anova : DataFrame
A DataFrame containing.
When args is a single model, DataFrame contains.
sum_sq : float64

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.

should be float if scalar, not a numpy type.

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.

Thanks for the comment, and the initial work you did about a year ago. Helped me get started on enhancing this docstring.

Unless I am understanding this incorrectly float64 will always return for every column. I even tried a one item model based on the example in the docstring.

>>> moore_lm = ols('conformity ~ fscore',  data=data).fit()
>>> table = sm.stats.anova_lm(moore_lm,typ=2)
>>> print(table)
               sum_sq    df         F    PR(>F)
fscore       0.134511   1.0  0.004784  0.945179
Residual  1209.065489  43.0       NaN       NaN
>>> table.dtypes
sum_sq    float64
df        float64
F         float64
PR(>F)    float64
dtype: object

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.

I see, each is a vector. So maybe DataFrame with columns: ?

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.

Added some clarity about the columns being returned.

commit 2e9cf7c

@bashtage

Copy link
Copy Markdown
Member

LGTM

@jbrockmendel jbrockmendel mentioned this pull request Sep 21, 2018
31 of 32 tasks
@josef-pkt

Copy link
Copy Markdown
Member

final version looks good to me

@jtweeder Can you squash this into one commit?

further pythonic cleansing, removed lmaps in place of list comps, removed lmap import not otherwise used

docstring changed to the only version that returns useful information the f-test

docstring change for multimodel anova, left off last commit.

fixing typo and correcting spacing

Futher clarity of dataframes returned.
@jtweeder

Copy link
Copy Markdown
Contributor Author

@josef-pkt I tried but apparently failed...as it now says i added two more commits..Sorry about that apparently I need more help than I anticipated. Hopefully I did not screw it up too much.

Thanks.

@josef-pkt

Copy link
Copy Markdown
Member

no problem I will fix it with an interactive rebase (hopefully within a few hours)
(I canceled the CI jobs for now)

@bashtage

Copy link
Copy Markdown
Member

Fixed version in #5246

@bashtage

Copy link
Copy Markdown
Member

Basically you should have done

git rebase -i upstream/master

and then in the dialog that pops up you should have changed it to

pick  BLAH 1
s       BLAH 2
s       BLAH 3
...
s       BLAH n

and then run the rebase. You then get to provide a final commit message for all commits.

@josef-pkt josef-pkt closed this in b6f7808 Sep 21, 2018
@jtweeder

Copy link
Copy Markdown
Contributor Author

Thanks for that...I will give that a run on my personal repos so it wont be so messy next time.

@josef-pkt

Copy link
Copy Markdown
Member

What I usually did, and still sometimes do for complicated git surgery, is to create a local temporary branch to try out whether the git rebase works correctly, and then either push the temporary branch to the right remote branch or redo the rebase on the original branch.
It was not unusual that I needed several tries until I got it right.

@bashtage

Copy link
Copy Markdown
Member

You can also just try push the last commit to origin/BRANCH-NAME, and try and rebase, and if it does wrong, git reset --hard origin/BRANCH-NAME to revert right before the rebase.

@jtweeder
jtweeder deleted the anova_doc_fix branch September 21, 2018 17:04
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ANOVA documentation clarity.

5 participants