[SciPy-Dev] scipy.stats: algorithm to for ticket 1493

nicky van foreest vanforeest@gmail....
Sun Apr 22 13:42:28 CDT 2012


I just realized, xa may be too large... hence we should search such
that cdf(left) < q < cdf(right).

*Assuming* that xa < 0 and xb > 0 the following should be better

def findppf(q):
    # search  until cdf(left) < q < cdf(right)
    left, right = invnorm.xa, invnorm.xb
    while invnorm.cdf(left, 7.24000019602, scale=2.51913630166) > q:
        right = left
        left *= 2
    while invnorm.cdf(right, 7.24000019602, scale=2.51913630166) < q:
        left = right
        right *= 2
    return optimize.brentq(lambda x: \
                           invnorm.cdf(x, 7.24000019602,
scale=2.51913630166) - q,\
                           left, right)

Should a test on xa < 0 and xb>0 be added?


More information about the SciPy-Dev mailing list