Skip to content

Allow qqplot_2samples to accept samples of unequal size - #4840

Closed
dsaxton wants to merge 0 commit into
statsmodels:masterfrom
dsaxton:master
Closed

dsaxton wants to merge 0 commit into
statsmodels:masterfrom
dsaxton:master

Conversation

@dsaxton

@dsaxton dsaxton commented Aug 7, 2018

Copy link
Copy Markdown

This tries to address issue #4832 where qqplot_2samples requires that both samples have the same size. Here if the function encounters samples of differing length it calculates the quantile function for the larger sample and then takes the estimated quantiles corresponding to the smaller sample using linear interpolation. These two samples (which now are of equal length) are then plotted in the usual way.

@coveralls

coveralls commented Aug 7, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 83.857% when pulling 934bdd1 on dsaxton:master into 1b1da38 on statsmodels:master.

@codecov-io

codecov-io commented Aug 7, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #4840 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4840      +/-   ##
==========================================
+ Coverage   81.32%   81.38%   +0.05%     
==========================================
  Files         581      581              
  Lines       90192    90214      +22     
  Branches     9361    10083     +722     
==========================================
+ Hits        73350    73417      +67     
+ Misses      14545    14504      -41     
+ Partials     2297     2293       -4
Impacted Files Coverage Δ
statsmodels/graphics/gofplots.py 83.69% <100%> (+1.34%) ⬆️
statsmodels/graphics/tests/test_gofplots.py 93.69% <100%> (+0.36%) ⬆️
statsmodels/sandbox/distributions/gof_new.py 0% <0%> (ø) ⬆️
statsmodels/sandbox/distributions/mv_normal.py 38.97% <0%> (ø) ⬆️
statsmodels/stats/descriptivestats.py 24.13% <0%> (ø) ⬆️
statsmodels/sandbox/bspline.py 0% <0%> (ø) ⬆️
statsmodels/sandbox/stats/multicomp.py 40.25% <0%> (ø) ⬆️
statsmodels/iolib/tests/test_table_econpy.py 100% <0%> (ø) ⬆️
statsmodels/tools/tests/test_grouputils.py 98.4% <0%> (+0.02%) ⬆️
statsmodels/tsa/statespace/mlemodel.py 86% <0%> (+0.11%) ⬆️
... and 11 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 1b1da38...934bdd1. Read the comment docs.

@bashtage

Copy link
Copy Markdown
Member

Need a minimial test that shows that the code executes when samples have different sizes.

Comment thread statsmodels/graphics/gofplots.py Outdated
self.dist, ax=ax, line=line,
**plotkwargs)
if self.nobs < other.nobs:
finv = interp1d([(i+1) / other.nobs for i in range(other.nobs)], other.sorted_data)

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.

This problem is completely symmetric. I should be possible to always fix the long series and then just call a single version of _do_plot

Comment thread statsmodels/graphics/gofplots.py Outdated
**plotkwargs)

else:
fig, ax = _do_plot(other.sample_percentiles,

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 use a single call here fo the forms

fig, ax = _do_plot(other_percentiles,
                                  self_percentiles,
                                   dist, ax=ax, line=line,
                                   **plotkwargs)

and then define other_percentiles, self_percentiles and dist correctly depending on the sample lengths.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, agreed. Will work on making that change.

Since within the if and elif statements we've already computed the corresponding quantiles for the larger sample in sorted order, would you recommend passing these directly to _do_plot instead of initializing a new ProbPlot and recomputing the percentiles?

Regarding the dist parameter, my understanding from looking over the code is that this is a theoretical distribution which wouldn't change depending on sample size and so we could leave this alone, but please let me know if I'm mistaken on this.

I'll also put together a minimal test for the proposed change.

@dsaxton

dsaxton commented Aug 14, 2018

Copy link
Copy Markdown
Author

It seems my tests are failing and I haven't been able to identify the issue. Any ideas as to what the cause might be?

@bashtage

bashtage commented Aug 14, 2018 •

Copy link
Copy Markdown
Member

Here is the fix.

  1. Add from __future__ import division as the first line in the file. This is just good practice.
  2. You need to use 1.0 instead of 1. Using 1.0 will promote everything to a float rather than doing integer math, which was producing lots of 0s. This only affects Python 2.7, not 3, and so you only failed there
            if self.nobs < other.nobs:
                finv = interp1d([(i+ 1.0) / other.nobs for i in range(other.nobs)],
                                other.sorted_data)
                q = finv([(i+1.0) / self.nobs for i in range(self.nobs)])
                self_percentiles = self.sample_percentiles
                other_percentiles = q

            elif other.nobs < self.nobs:
                finv = interp1d([(i+1.0) / self.nobs for i in range(self.nobs)],
                                self.sorted_data)
                q = finv([(i+1.0) / other.nobs for i in range(other.nobs)])
                self_percentiles = q
                other_percentiles = other.sample_percentiles

@dsaxton

dsaxton commented Aug 14, 2018

Copy link
Copy Markdown
Author

Great, thanks so much. from __future__ import division always struck me as a strange incantation. Quick question, but should I be concerned that the LGTM analysis always fails?

@bashtage

Copy link
Copy Markdown
Member

LGTM is broken and should be ignored. Only appveyor and travis really matter.

@dsaxton

dsaxton commented Aug 18, 2018

Copy link
Copy Markdown
Author

@bashtage I noticed that there seem to be merge conflicts for this pull request, is this something that I should resolve (I am still very new to making pull requests, this was actually my first ever)?

@dsaxton

dsaxton commented Aug 18, 2018 •

Copy link
Copy Markdown
Author

@bashtage It seems that the merge conflict stems from a couple aesthetic / readability changes I made to test_gofplots.py related to alignment and spacing. In the future I won't make these modifications as part of an unrelated set of changes and will instead offer them as separate pull requests.

@bashtage

Copy link
Copy Markdown
Member

You need to rebase your commit ontop of master.

It can be a bit tricky. You can do

git add remote upstream https://github.com/statsmodels/statsmodels
git fetch --all
git rebase upstream/master

git add statsmodels/graphics/tests/test_gofplots.py
git rebase --continue
git push -f

If something goes wrong you can do git rebase --abort instead of --continue

@bashtage

Copy link
Copy Markdown
Member

You you think you need help I or @josef-pkt could do the rebase.

@dsaxton

dsaxton commented Aug 18, 2018

Copy link
Copy Markdown
Author

@bashtage Ok, I will try this. Should it be git remote add upstream... rather than git add remote upstream... by chance? I get an error with the latter command.

@bashtage

bashtage commented Aug 18, 2018 via email

Copy link
Copy Markdown
Member

@dsaxton

dsaxton commented Aug 18, 2018

Copy link
Copy Markdown
Author

Ok, I'm trying to manually resolve a merge conflict and I notice the test decorators seem to have gone from @skipif... to @pytest.mark.skipif..., so I'm assuming I should use the pytest decorators.

@bashtage

bashtage commented Aug 18, 2018 via email

Copy link
Copy Markdown
Member

@dsaxton

dsaxton commented Aug 18, 2018

Copy link
Copy Markdown
Author

Thanks, hopefully I didn't botch that.

@dsaxton

dsaxton commented Aug 19, 2018

Copy link
Copy Markdown
Author

@bashtage It looks like the checks failed because of a test test_transform_dataframe . I'm assuming this is unrelated to this particular PR?

@bashtage

Copy link
Copy Markdown
Member

These are unrelated to your code changes.

@josef-pkt I think this is ready.

@dsaxton

dsaxton commented Aug 26, 2018

Copy link
Copy Markdown
Author

@josef-pkt Are there any additional changes I should make to this pull request?

@dsaxton dsaxton closed this Sep 7, 2018
@bashtage

bashtage commented Sep 8, 2018

Copy link
Copy Markdown
Member

@dsaxton Did you mean to close this? I think it is ready and will get merged. Merging can be very slow around here, but it doesn't mean that it isn't welcome.

@josef-pkt

Copy link
Copy Markdown
Member

I would like to get this or something like this into statsmodels in the next week.
Probability plots are on my current schedule, when I'm not getting distracted.

@dsaxton

dsaxton commented Sep 8, 2018

Copy link
Copy Markdown
Author

It was an accident. I reset my local master branch to resemble upstream master when creating a new branch for another pull request, but forgot that it would also reset these changes.

@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.

5 participants