Re: Q: on scipy probplot user defined distribution function (solution)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Q: on scipy probplot user defined distribution function (solution)

Sergio Rojas
> From: Paul Hobson <[hidden email]>

> Hmm. I don't think scipy needs to know about your distribution per se. You
>

Thanks for sharing your thoughts, Paul. I finally found the
way to go. As you mention, the parameter "dist" is wher one needs
to specify our own distribution. The key is to give it without quotes.
Here is a working example:


import matplotlib.pyplot as plt #prefer this
import numpy as np
from scipy import stats

class mydist(object):
    def pdf(x):
        "define and return the pdf"
        return  stats.norm.pdf(x)
    def cdf(x):
        "define and return the cdf"
        return  stats.norm.cdf(x)
    def ppf(x):
        "define and return the ppf"
        return  stats.norm.ppf(x)

mymean = 1.0
myvar = 1.0
n = 5000
colData = np.random.normal(mymean, myvar, n)

"""
   It took me a while to realize that the quotes surrounding
   the distribution should not be there when using a user defined one
"""
print(' ProbPlot using system norm ')
res = stats.probplot(colData, dist="norm", plot=plt, rvalue=True)
plt.show()

# To use our own defined distribution remove the quotes around the name:

print(' ProbPlot using my redefined system norm ')
res = stats.probplot(colData, dist=mydist, plot=plt, rvalue=True)
plt.show()


Sergio
------------------------------

Message: 2
Date: Thu, 5 Jul 2018 00:11:52 -0700
From: Paul Hobson <[hidden email]>
To: SciPy Users List <[hidden email]>
Subject: Re: [SciPy-User] Q: on scipy probplot user defined
distribution function
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="utf-8"

Hmm. I don't think scipy needs to know about your distribution per se. You
just need to be able to pass it to the probplot function via the `dist`
parameter. Per the docs (
https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.probplot.html[https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.probplot.html]
):

scipy.stats.probplot(*x*, *sparams=()*, *dist='norm'*, *fit=True*,
*plot=None*)[source]
<http://github.com/scipy/scipy/blob/v0.14.0/scipy/stats/morestats.py#L296[http://github.com/scipy/scipy/blob/v0.14.0/scipy/stats/morestats.py#L296]>
[snip]

*dist* : str or stats.distributions instance, optional

Distribution or distribution function name. The default is ?norm? for a
normal probability plot. Objects that look enough like a
stats.distributions instance (i.e. they have a ppf method) are also
accepted.

[snip]

On Wed, Jul 4, 2018 at 12:19 PM Sergio Rojas <[hidden email]> wrote:

>
> > Here's an example of using different distributions with the mpl-probscale
> > package:
> >
> https://matplotlib.org/mpl-probscale/tutorial/closer_look_at_viz.html#using-different-distributions-for-your-scales[https://matplotlib.org/mpl-probscale/tutorial/closer_look_at_viz.html#using-different-distributions-for-your-scales][https://matplotlib.org/mpl-probscale/tutorial/closer_look_at_viz.html#using-different-distributions-for-your-scales[https://matplotlib.org/mpl-probscale/tutorial/closer_look_at_viz.html#using-different-distributions-for-your-scales]]
>
> > -Paul
>
> Thanks, Paul. I guess I might need to build a <dist>.pdf, .cdf, and .ppf
> files for my distribution. What is not clear is how to specify the
> alternative
> directory to make them available to scipy
>
> On Mon, Jul 2, 2018 at 11:40 AM Sergio Rojas <[hidden email]> wrote:
>
> > Hello folks,
> >
> > How can one specify our own (user made) probability distribution
> > function to scipy.stats.probplot ?
> >
> > Can it be done is the pdf used is not in a closed form function
> > (meaning that the random drawings comes from a numerical
> > procedure)?
> >
> > Salut,
> >
> >
> > Sergio
> > _______________________________________________
> > SciPy-User mailing list
> > [hidden email]
> >
> https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user][https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user]]
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/scipy-user/attachments/20180702/8522d0d0/attachment-0001.html[http://mail.python.org/pipermail/scipy-user/attachments/20180702/8522d0d0/attachment-0001.html][http://mail.python.org/pipermail/scipy-user/attachments/20180702/8522d0d0/attachment-0001.html[http://mail.python.org/pipermail/scipy-user/attachments/20180702/8522d0d0/attachment-0001.html]]
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
>
> https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user][https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user]]
>
>
> ------------------------------
>
> End of SciPy-User Digest, Vol 179, Issue 1
> ******************************************
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20180705/eee7e894/attachment-0001.html[http://mail.python.org/pipermail/scipy-user/attachments/20180705/eee7e894/attachment-0001.html]>

------------------------------

Subject: Digest Footer

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user[https://mail.python.org/mailman/listinfo/scipy-user]


------------------------------

End of SciPy-User Digest, Vol 179, Issue 2
******************************************
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user