Skip to content

Calculate adjusted p-values for Tukey HSD Test - #5418

Closed
AndrewDDavis wants to merge 6 commits into
statsmodels:masterfrom
AndrewDDavis:tukey-pvals
Closed

AndrewDDavis wants to merge 6 commits into
statsmodels:masterfrom
AndrewDDavis:tukey-pvals

Conversation

@AndrewDDavis

Copy link
Copy Markdown
Contributor
  1. calculate adjusted p-values when using the tukeyhsd function
  2. add the p-vals to the results table and as an attribute of the TukeyHSDResults object

@AndrewDDavis AndrewDDavis changed the title Calculate adjusted p-values when for Tukey HSD Test Calculate adjusted p-values for Tukey HSD Test Dec 11, 2018
@coveralls

coveralls commented Dec 11, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.02%) to 84.216% when pulling 08dbe2b on AndrewDDavis:tukey-pvals into 428b49c on statsmodels:master.

Comment thread statsmodels/sandbox/stats/multicomp.py Outdated
return qsturng(1-alpha, k, df)


def get_tukeyPval(k, df, q):

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.

pep-8 names (no capital letters and no camel case in function names)
e.g. get_tukey_pvalue

Comment thread statsmodels/sandbox/stats/multicomp.py Outdated
std_pairs : standard deviation of pairwise mean differences
q_crit : critical value of studentized range statistic at given alpha
halfwidths : half widths of simultaneous confidence interval
p_adjs : adjusted p-values

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.

name: p_adjs -> pvalues
pvalues should be spelled out instead of just one letter p.
I think, given that the function or class has already TukeyHSD in the name, we don't need to add _adjusted to the name.

@josef-pkt

Copy link
Copy Markdown
Member

Looks good based on reading through it, but I need to go through the details to understand the code path that this takes.
needs unit tests, it should be possible to add an assert for the pvalues to an existing unit test.

only comment so far is to make names more explicit and follow more python style

@AndrewDDavis Thanks for this enhancement, it has waited for implementation for a long time.

@codecov

codecov Bot commented Dec 13, 2018

Copy link
Copy Markdown

Codecov Report

Merging #5418 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5418      +/-   ##
==========================================
+ Coverage   81.75%   81.76%   +0.01%     
==========================================
  Files         569      569              
  Lines       89851    89856       +5     
  Branches    10022    10022              
==========================================
+ Hits        73455    73473      +18     
+ Misses      14126    14118       -8     
+ Partials     2270     2265       -5
Impacted Files Coverage Δ
statsmodels/sandbox/stats/multicomp.py 40.78% <100%> (+0.52%) ⬆️
statsmodels/regression/mixed_linear_model.py 89.77% <0%> (+0.79%) ⬆️
statsmodels/stats/libqsturng/qsturng_.py 90.04% <0%> (+1.99%) ⬆️

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 428b49c...04da95c. Read the comment docs.

@codecov

codecov Bot commented Dec 13, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5418 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5418      +/-   ##
==========================================
- Coverage   81.75%   81.72%   -0.03%     
==========================================
  Files         569      569              
  Lines       89851    89851              
  Branches    10022    10022              
==========================================
- Hits        73455    73431      -24     
- Misses      14126    14150      +24     
  Partials     2270     2270
Impacted Files Coverage Δ
statsmodels/stats/tests/test_multi.py 100% <100%> (ø) ⬆️
statsmodels/sandbox/stats/multicomp.py 40.78% <100%> (+0.52%) ⬆️
statsmodels/iolib/openfile.py 66.66% <0%> (-9.1%) ⬇️
statsmodels/base/wrapper.py 86.95% <0%> (-4.35%) ⬇️
statsmodels/datasets/utils.py 80.24% <0%> (-3.09%) ⬇️
statsmodels/tsa/tsatools.py 87.3% <0%> (-2.48%) ⬇️
statsmodels/tsa/base/tsa_model.py 87.03% <0%> (-2.32%) ⬇️
statsmodels/iolib/tests/test_foreign.py 96.85% <0%> (-1.58%) ⬇️
statsmodels/iolib/foreign.py 71.23% <0%> (-1.39%) ⬇️
statsmodels/graphics/regressionplots.py 81.2% <0%> (-0.47%) ⬇️
... and 13 more

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 428b49c...08dbe2b. Read the comment docs.

@josef-pkt josef-pkt added this to the 0.10 milestone Dec 13, 2018
@AndrewDDavis

AndrewDDavis commented Dec 13, 2018 •

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look, I made the requested changes. The camel case was in there because I was attempting to follow the convention of the function names above it, but I certainly prefer to follow pep-8 also.

I took a crack at the test. The values diverge quite a bit for higher p-values, but are within 10^-4 on the smaller ones -- 0.113 being the highest of the values I arbitrarily considered "small".

Comment thread statsmodels/stats/tests/test_multi.py Outdated

# check p-values (divergence of high values is expected)
small_pvals_idx = [2, 5, 7, 9]
assert_almost_equal(res[small_pvals_idx, 3], myres[8][small_pvals_idx], decimal=4)

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.

It's better to use assert_allclose because it gives more flexibility
assert_almost_equal is old code from before assert_allclose was added to numpy.testing.

(history: we have been using assert_allclose for new code, but are slow, i.e. no concentrated effort, to change the old asserts.)

@josef-pkt

Copy link
Copy Markdown
Member

I won't have time to substantially review this until after Christmas break (*). It looks good to me, but I'd better check the details. However, I scheduled it for 0.10 because I think it can be merged fast and is a long requested improvement.

(*) moving a family of five to a new house that isn't quite finished with the renovation yet.

about the p-values: Numerical approximation to non-standard distributions often focus on the relevant range <= 0.1 (and >= 0.001), and are less careful in the larger range. So larger differences across packages in that range are not a surprise.

@bashtage bashtage mentioned this pull request May 6, 2019
4 tasks done
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.

3 participants