[SciPy-user] computing Bayesian credible intervals

Neil Martinsen-Burrell nmb at wartburg.edu
Fri May 2 16:04:09 EDT 2008


Johann Cohen-Tanugi <cohen <at> slac.stanford.edu> writes:

> hi Neil, thanks for your answer and sorry I was not clear enough. Of 
> course I require the 2 conditions. 1) defines *a* credible interval if p 
> is a posterior pdf; and 2) sets a constraint that for common situation 
> yield *the* standard Bayesian credible interval. I will have a look at 
> brentq, I do not know what it refers to.

scipy.optimize.brentq is Brent's method for finding a root of a given scalar
equation.  Since you are looking for two values, a and b, with two conditions,
then Brent's method is not appropriate (barring some symmetry-based reduction to
one variable).  I like to use scipy.optimize.fsolve to find roots of
multivariable equations, such as

def solve_me(x): # x is an array of the values you are solving for
    a,b = x
    integral_error = quad(density, a , b) - q
    prob_difference = density(b) - density(a)
    return np.array([integral_error, prob_difference])

fsolve(solve_me, [0.0, 1.0])  # initial guess is a = 0, b = 1







More information about the SciPy-User mailing list