[SciPy-user] How to get a ppf for scipy.stats.beta

joep josef.pktd@gmail....
Fri Sep 19 08:40:31 CDT 2008


Scaling is done through the ``scale`` keyword, not through ``size``,
``size`` refers to sample size for rvs

I think what you want is this:

Use distribution function directly, not frozen:

>>> beta.cdf(2371,a,b,scale=n)
array(0.59995766129911532)
>>> beta.ppf(0.6,a,b,scale=n)
array(2371.1617428411146)

Freeze the distribution at the distribution parameters, but not at the
value (x) at which you want to evaluate cdf, ppf,..
In your case the x was fixed at the initially defined values

>>> beta(a,b,scale=n).cdf(2371)
array(0.59995766129911532)
>>> beta(a,b,scale=n).ppf(0.6)
array(2371.1617428411146)

>>> B = beta(a,b,scale=n)
>>> B.cdf(2371)
array(0.59995766129911532)
>>> B.ppf(0.6)
array(2371.1617428411146)

Josef
On Sep 19, 8:52 am, "David Huard" <david.hu...@gmail.com> wrote:
> Hi Michael,
>
> calling beta(a, b) will generate a "frozen distribution", that is one whose
> parameters are fixed by you:
>
> B = beta(a, b)   # note that you should't pass x at this stage.
>
> B.pdf(x)
> B.cdf(x)
>
> Now if you want to sample from the Beta, simply use the rvs method:
>
> B.rvs(1000)
>
> You can also simply do
>
> beta.rvs(a,b,size=1000)
>
> HTH,
>
> David
>
> On Fri, Sep 19, 2008 at 5:58 AM, Michael <mnand...@blueyonder.co.uk> wrote:
> > Hi list,
>
> > i am trying to use the percent point function to sample from the cdf for
> > a beta distribution
>
> > beta.ppf() returns an array instead of x; also you cannot create a ppf
> > using the same idiom as beta.cdf(x,a,b,size=n)
>
> > How do i go about getting the ppf for a beta dist?
>
> > thanks in advance - much hairpulling on this <grr>
>
> > Michael
>
> > from scipy.stats import norm
> > from scipy.stats import beta
> > from scipy import linspace
>
> > print norm.cdf(1.2)             # 0.884930329778
> > print norm.ppf(0.884930329778)  # 1.2
>
> > a=2
> > b=7
> > n=10e3
> > x=linspace(0,1,n)
>
> > cdf=beta.cdf(x,a,b,size=n)
> > print cdf[2371]                 # 0.6
>
> > B=beta(x,a,b,size=n)
>
> > print B.cdf(2371)
> > print B.ppf(0.6)                # <-- should be 2371?
>
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-u...@scipy.org
> >http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-u...@scipy.orghttp://projects.scipy.org/mailman/listinfo/scipy-user


More information about the SciPy-user mailing list