Repository navigation
ENH: Add games howell test - #7332
ameliajtaylor wants to merge 4 commits into
Conversation
bashtage
left a comment
There was a problem hiding this comment.
There seem to be some unnecessary imports.
| from collections import defaultdict | ||
|
|
||
| import numpy as np | ||
| import networkx as nx |
There was a problem hiding this comment.
networkx is not a dependency of statsmodels.
There was a problem hiding this comment.
Good catch. I forgot to add that/bring this up. As you note below, it is only used for visualizing the results of the test. I see 4 options
- add the dependency
- leave out the visualization,
- keep the visualization and re-implement the underlying algorithm for finding cliques in a graph (or following this paper, which boils down to cliques in a graph).
- follow the model of
plot_simultaneousinTukeyHSDResultsinstatsmodels.sandbox.stats.multicomp.pywhich usesmatplotlibbut the module itself does not import it and there is not test for it and thus the visualization support is there, but statsmodels does not have matplotlib as a dependency.
Maybe #4 is best? I'm reluctant to give up the visualization for the reasons I put in the other comment.
There was a problem hiding this comment.
number 4 is fine, just import in the function
and make unit test conditional on availability of nx.
We do the same for matplotlib, where we have mostly only smoke test for plot functions and plot methods.
cvxopt is another optional dependency that has imports and unit tests conditional on availability
| """ | ||
| return pd.DataFrame(self._results) | ||
|
|
||
| def connecting_letters(self, sig_level = 0.05): |
There was a problem hiding this comment.
Is this important here? It is the only use of nx. Doesn't seem to be related to the test.
There was a problem hiding this comment.
This is a good discussion to have. You are correct, we can add the statistical test without this function. However, both JMP and R have such a report for Tukey and it makes using the results much much easier.
And if we agree to keep it, we should discuss the name of this function, since I'm not sure we can use the same name as what JMP calls it (I meant to rename before posting the PR and forgot) and discuss where it should live --- in this implementation it can only be applied to Games Howell results, but with a bit of refactoring of the Tukey code and some abstraction here it could be used to visualize results from either test and is really helpful for such visualization (I decided not to do that before posting as it requires some other minor, but non-zero refactoring of existing code and thought that might be better as a follow-up PR, and it is arguable it should be done as part of this PR --- I can do it without changing impacting the existing API for either pairwise_tukeyhsd or pairwise_games_howell).
I use networkx because the algorithm for this is to compute cliques in a graph. To remove that dependency and keep this visualization of the results would require re-implementing that algorithm.
There was a problem hiding this comment.
It possibly could be added as a soft dependency. Would need to consult @josef-pkt . In this case, networkx would only be imported in the function where it is needed in a try, except ImportError, and if not available a "friendly" error message would be given to users to tell them that networkx is required but not available.
There was a problem hiding this comment.
I haven't looked at the details yet. I've never seen a graph representation for this.
I have a function (in a PR ?) that assigns letters to individual groups, for a standard linear display (list of letters as grouping).
Maybe we can just return some structure that users can feed directly to nx instead of us doing it.
Otherwise we make it optional and build graph if nx is available.
There was a problem hiding this comment.
@josef-pkt can you point me to that function. I think it is doing something fundamentally different from this, but without looking I'm not sure. The issue here is the algorithm --- I use a dataframe to display the results/return it to the user. I'm using networkx to find the cliques in the graph that tell you how the groups are connected. I need to look again at what the raw return is from the find_cliques function in nx is to see how user friendly, or not that might be.
I personally, like @bashtage's suggestion to use a try, except, ImportError with a graceful/friendly fail to help users and understand if that's not considered an option. Note that plot_simultaneous in TukeyHSDResults requires matplotlib and has none of this --- I'm not saying we should follow that pattern, rather to say we should set the pattern here we want in other cases, like that, for the future.
|
piepo grouping letter assignment is in #3674 |
|
@josef-pkt That looks to be the same thing. I will do some testing on it with my examples that I know caused problems for a JMP extension. And then, assuming all goes well when I dig in, I'll likely remove that feature from this PR and do the work on your code to figure out where to put it and how to connect it (I have an idea that is better than what I did here). The idea being that I am cribbing off of the fact that you can use clique algorithms to do this, but you implemented it yourself (the part I didn't want to do), so now we can combine forces! |
|
|
||
| def groupdemean(self): | ||
| """groupdemean""" | ||
| def groupedmean(self): |
There was a problem hiding this comment.
it's not a grouped_mean
it's group_demean, i.e. data is demeaned by groups (i.e. residual of a group indicator model)
|
games-howell has been merged in #9487 as an extension to tukey-hsd (instead of using a separate implementation) still extra in this PR: unit test case and letter codes |
NumPy's guide.
Adding the Games Howell Post Hoc Test. This is not currently implemented in R or JMP (though there is an add one can get) and AFAIK no other packages. However, as I note in the tests, you can easily use this R pub to code up the same test (the pub suggests there is a package one can use, but it does not work, it's better to use the code snippet) and verify the test values. I added screenshots in the details section below of the results in R using the code linked for the test I included in the PR and the results of using R version of connecting letters for the test added for that.
Because this test is an alternative to Tukey HSD but does not assume equal variances and sample sizes, I followed the code for that statistical test (as per a discussion in the google group) as a model for where to put functions/add them to classes, etc. as well as for the tests. This may not be optimal, but follows existing patterns while making sure all new code is well documented and uses
blackfor style.Details
R Games Howell resultsR connecting letters results (the R package calls it

multcompLetters)Notes:
needed for doc changes.
then show that it is fixed with the new code.
verify you changes are well formatted by running
flake8is installed. This command is also available on Windowsusing the Windows System for Linux once
flake8is installed in thelocal Linux environment. While passing this test is not required, it is good practice and it help
improve code quality in
statsmodels.