def lift_credible_interval(variations, control=None, level=95,
                           sample_size=SAMPLE_SIZE):
    """Calculate credible interval for lift E[(B-A)/A] using MCMC.

    Returns a 3-tuple (lower, median, upper)
    """
    values = OrderedDict()
    a, others = _split(variations, control)

    for label, b in others.items():
        a_samples = a.posterior.rvs(size=sample_size)
        b_samples = b.posterior.rvs(size=sample_size)
        lift_samples = (b_samples-a_samples)/a_samples
        left_percentile = 0.5*(100-level)
        right = np.percentile(lift_samples, level+left_percentile)
        median = np.percentile(lift_samples, 50)
        left = np.percentile(lift_samples, left_percentile)
        values[label] = min(left, right), median, max(left, right)

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