def dominance(variations, control=None, sample_size=SAMPLE_SIZE):
    """Calculate P(A > B).

    Uses a modified Evan Miller closed formula if prior parameters are integers
    http://www.evanmiller.org/bayesian-ab-testing.html

    Uses scipy's MCMC otherwise

    TODO: The modified formula for informative prior has to be proved correct
    """
    values = OrderedDict()
    a, others = _split(variations, control)

    def is_integer(x):
        try:
            return x.is_integer()
        except:
            return int(x) == x

    for label, b in others.items():

        # If prior parameters are integers, use modified Evan Miller formula:
        if is_integer(a.prior_alpha) and is_integer(a.prior_beta) \
           and is_integer(b.prior_alpha) and is_integer(b.prior_beta):

            total = 0
            for i in range(b.alpha-b.prior_alpha):
                total += np.exp(spc.betaln(a.alpha+i, b.beta + a.beta) -
                                np.log(b.beta+i) - spc.betaln(b.prior_alpha+i,
                                b.beta) - spc.betaln(a.alpha, a.beta))
            values[label] = total

        # Use MCMC otherwise
        else:
            a_samples = a.posterior.rvs(sample_size)
            b_samples = b.posterior.rvs(sample_size)
            values[label] = np.mean(b_samples > a_samples)

    return values
dataset/ETHPy150Open bogdan-kulynych/trials/trials/stats.py/dominance/original