def test_mjci(self):
     "Tests the Marits-Jarrett estimator"
     data = ma.array([
         77, 87, 88, 114, 151, 210, 219, 246, 253, 262, 296, 299, 306, 376,
         428, 515, 666, 1310, 2611
     ])
     assert_almost_equal(ms.mjci(data), [55.76819, 45.84028, 198.87875], 5)
def calculate_RCIW_MJ_HD(data, prob=0.5, alpha=0.01, axis=None):
    """
    Computes the alpha confidence interval for the selected quantiles of the data, with Maritz-Jarrett estimators.
    :param prob:
    :param alpha:
    :param axis:
    :return:
    """
    if len(data) < 2:
        return -1

    if variance(data) == 0.0:
        return 0.0

    alpha = min(alpha, 1 - alpha)
    z = norm.ppf(1 - alpha / 2.)
    xq = hdquantiles(data, prob, axis=axis)
    med = round(xq[0], 5)
    if med == 0:
        return 0.0

    smj = 0.0

    try:
        smj = mjci(data, prob, axis=axis)
    except:
        return 0.0

    ci_bounds = (xq - z * smj, xq + z * smj)
    ci_lower = ci_bounds[0][0]
    ci_lower = 0 if ci_lower < 0 else ci_lower
    ci_upper = ci_bounds[1][0]
    ci_upper = 0 if ci_upper < 0 else ci_upper

    rciw = ((ci_upper - ci_lower) / med) * 100

    return rciw
 def test_mjci(self):
     "Tests the Marits-Jarrett estimator"
     data = ma.array([ 77, 87, 88,114,151,210,219,246,253,262,
                       296,299,306,376,428,515,666,1310,2611])
     assert_almost_equal(ms.mjci(data),[55.76819,45.84028,198.87875],5)