5

I need to get the Nth quantile of a beta distribution, or equivalently, the 95% or 99% percentile. This is so much easier in Maple, which allows symbolic input -- but how is this done in Python?

I've searched stackoverflow, and it seems that people are often concerned with the normal distribution only.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
irene
  • 2,085
  • 1
  • 22
  • 36

2 Answers2

6

I ended up with the ppf instead:

scipy.stats.beta.ppf(prob,2,N-2)
irene
  • 2,085
  • 1
  • 22
  • 36
1

You can compute the quantile of a beta distribution with the following function:

from scipy.stats import beta
import numpy as np
a, b = 2.31, 0.627
x = np.linspace(beta.ppf(0.01, a, b), beta.ppf(0.99, a, b), 100)
distribution=beta.pdf(x, a, b)
def quantile(x,quantiles):
    xsorted = sorted(x)
    qvalues = [xsorted[int(q * len(xsorted))] for q in quantiles]
    return zip(quantiles,qvalues)
quantiles = quantile(distribution,[0.05,0.16,.5,.84, 0.95])
Dalek
  • 4,168
  • 11
  • 48
  • 100