Skip to content

ENH: qqplot - #4

Closed
chrisjordansquire wants to merge 8 commits into
statsmodels:masterfrom
chrisjordansquire:qqplot
Closed

chrisjordansquire wants to merge 8 commits into
statsmodels:masterfrom
chrisjordansquire:qqplot

Conversation

@chrisjordansquire

Copy link
Copy Markdown

A qqplot function. It plots the quantiles of a data vector against the theoretical quantiles of a specified distribution. The user can either give specific parameters for this distribution or let python fit them automatically.

Comment thread scikits/statsmodels/graphics/qqplot.py Outdated

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.

stray print

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.

Thanks.

@josef-pkt

Copy link
Copy Markdown
Member

I think after correcting the change in args kwargs in the function body, this should be good to be merged

Thanks Chris

@chrisjordansquire

Copy link
Copy Markdown
Author

Ok. I think I've made all the changes you mentioned. Other than the axes one. (Which I think I still don't quite understand. I don't think I'm familiar enough with matplotlib, and I couldn't figure it out even after spending a bit of time on their man pages.)

@chrisjordansquire

Copy link
Copy Markdown
Author

I looked at the examples in the doc strings again and realized the x-margins weren't always large enough. I fixed that, but now they're sometimes a little too large. I'm not sure how to find a good medium, short of scaling the x-limits manually.

@chrisjordansquire

Copy link
Copy Markdown
Author

Unless there are other requests, though, I don't think I'm going to make any further changes.

@jseabold

Copy link
Copy Markdown
Member

Sorry, I thought I was getting notifications on comments. Apparently not. If you want to get my attention, I think you need to do @jseabold. Don't hit the merge button. From what I understand it almost never does what you'd expect. See

http://thread.gmane.org/gmane.comp.python.scientific.devel/15193/

@chrisjordansquire

Copy link
Copy Markdown
Author

Um....I don't think I follow your comment skipper. Who was it directed to?

@jseabold

Copy link
Copy Markdown
Member

Josef. He asked if he could just hit the merge button.

@jseabold

Copy link
Copy Markdown
Member

I'm going to go ahead and apply this.

I recall now where I left off with my version. It is recommended to use something like (i - a)/(nobs - 2a + 1) for the plotting positions of the theoretical quantiles where a = .5, .375 or 0 (attributed to Hazen, Blom and Gumbel and Weibull, respectively) rather than linspace. R has the function ppoints. This is so that the median gets a percentile rank of 50% and the tails are treated symmetrically I believe. I will make this change.

I'm not sure I understand why we don't want to plot a reference line. I agree that it doesn't have to be a 45-degree line, but the whole point, IIUC, of a diagnostic plot is to compare against the reference line and see where the deviations occur. This could be achieved generically by scaling your end_pts I think. We can keep it optional, but we need to scale end_pts for it to work correctly in all cases I think. I'll post a patch for this too.

Other than that looks good. Thanks for the patch.

@chrisjordansquire

Copy link
Copy Markdown
Author

The main reason I don't want to automatically draw a reference line is that I don't know of a particularly good way to draw one that applies in all cases. The two immediate ones I can think of, drawing a line between the 25% and 75% points and fitting an OLS lines to it, both have their merits. And I've wanted each of them in different cases.

@josef-pkt

Copy link
Copy Markdown
Member

Skipper,
I wasn't sure whether there are "plotting positions" in QQ-Plots, Nist handbook doesn't mention them.
But now I saw them in R package POT, with plotting positions appropriate for GPD, generalized pareto distribution.

I think, if you add plotting positions, then we should make them a keyword choice, and fix scipy.stats probability plot in the same way (at least one ticket in scipy trac asks for it). Plotting positions should be in the sandbox, based on Pierre's version in scipy.stats.mstats and his climate/hydrology scikit.

@jseabold

Copy link
Copy Markdown
Member

Either way, if you do line without fit, that surely isn't what you want. Ie.,

fig = sm.qqplot(res, line=True)
plt.show()

I was thinking of changing end_pts in this case to something like

end_pts = np.array(end_pts)
plt.plot(end_pts, end_pts*data.std() + data.mean(), 'r-')

Just so there is a sensible default. Thoughts?

On Thu, Aug 25, 2011 at 1:27 PM, chrisjordansquire
[email protected]
wrote:

The main reason I don't want to automatically draw a reference line is that I don't know of a particularly good way to draw one that applies in all cases. The two immediate ones I can think of, drawing a line between the 25% and 75% points and fitting an OLS lines to it, both have their merits. And I've wanted each of them in different cases.

Reply to this email directly or view it on GitHub:
#4 (comment)

@jseabold

Copy link
Copy Markdown
Member

In this case, the plotting positions are from np.linspace. Ie., the
positions at which we get the expected order statistics. R has them in
qqline/qqnorm as well. I was thinking just to make a, in the plotting
position formula (going back to 1914, AFAICT), a keyword.

On Thu, Aug 25, 2011 at 1:38 PM, josef-pkt
[email protected]
wrote:

Skipper,
I wasn't sure whether there are "plotting positions" in QQ-Plots, Nist handbook doesn't mention them.
But now I saw them in R package POT, with plotting positions appropriate for GPD, generalized pareto distribution.

I think, if you add plotting positions, then we should make them a keyword choice, and fix scipy.stats probability plot in the same way (at least one ticket in scipy trac asks for it). Plotting positions should be in the sandbox, based on Pierre's version in scipy.stats.mstats and his climate/hydrology scikit.

Reply to this email directly or view it on GitHub:
#4 (comment)

@jseabold

Copy link
Copy Markdown
Member

Ah, yes, Pierre's is the same.

On Thu, Aug 25, 2011 at 1:46 PM, Skipper Seabold [email protected] wrote:

In this case, the plotting positions are from np.linspace. Ie., the
positions at which we get the expected order statistics. R has them in
qqline as well. I was thinking just to make a, in the plotting
position formula (going back to 1914, AFAICT), a keyword.

On Thu, Aug 25, 2011 at 1:38 PM, josef-pkt
[email protected]
wrote:

Skipper,
I wasn't sure whether there are "plotting positions" in QQ-Plots, Nist handbook doesn't mention them.
But now I saw them in R package POT, with plotting positions appropriate for GPD, generalized pareto distribution.

I think, if you add plotting positions, then we should make them a keyword choice, and fix scipy.stats probability plot in the same way (at least one ticket in scipy trac asks for it). Plotting positions should be in the sandbox, based on Pierre's version in scipy.stats.mstats and his climate/hydrology scikit.

Reply to this email directly or view it on GitHub:
#4 (comment)

@jseabold

Copy link
Copy Markdown
Member

I am going to close this and commit the pull request and then make my proposed patches. We can continue the discussion there on the commits.

@jseabold jseabold closed this in 4894430 Aug 25, 2011
rgommers pushed a commit to rgommers/statsmodels that referenced this pull request Oct 12, 2012
Fixes / typos / small improvements for PR-408.
PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this pull request Sep 2, 2014
* qqplot:
  BUG: Made x-margins larger
  ENH/BUGS: Added line, removed *args and *kwargs
  BUGS: removed *args and *kwargs
  Changed args; tests only run with matplotlib
  BUGS: Corrected a couple of minor bugs
  Added fit to qqplot
  DOC: Added a bit of docs
  ENH:qqplot against scipy.stats dist
kshedden pushed a commit to kshedden/statsmodels that referenced this pull request Sep 11, 2018
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
@ameliajtaylor ameliajtaylor mentioned this pull request Feb 19, 2021
3 of 4 tasks
@gmcmacran gmcmacran mentioned this pull request Feb 25, 2022
4 tasks
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.

4 participants