pythonrnumpyscipybeta-distribution

How to integrate beta distribution in Python


In R, the following is used to calculate the integral between points 0 and 0.5 on beta distribution with the parameters 10 and 20:

 integrate(function(p) dbeta(p,10,20),0,0.5)

The result is:

0.9692858 absolute error < 6.6e-08

How can this be done in Python?


Solution

  • You can use the .cdf attribute of scipy.stats.beta. For a proper interval use the difference, e.g.

    betacdf = scipy.stats.beta(10,20).cdf
    betacdf(0.5)-betacdf(0.2)
    # 0.9200223098258666