def short_hdi(sample, cred=0.95):
    sorted_sample = sorted(sample)
    ci_index = int(cred * len(sorted_sample))  # Uses 'int()' for R's 'floor()'
    num_ci = len(sorted_sample) - ci_index

    ci_width = []
    for i in range(num_ci):
        width = sorted_sample[i + ci_index] - sorted_sample[i]
        ci_width.append(width)

    hdi_min = sorted_sample[ci_width.index(min(ci_width))]
    hdi_max = sorted_sample[ci_width.index(min(ci_width)) + ci_index]
    hdi_lim = (hdi_min, hdi_max)
    return hdi_lim
Calculate the shortest Highest Density Interval from
dataset/ETHPy150Open erikson84/BayesDataAnalysisWithPyMC/BayesDataAnalysisWithPymc/short_hdi.py/short_hdi