Esempio n. 1
0
def test_quantile_CI_monotone_alpha(args):
    X, q, alpha = args

    alpha1, alpha2 = sorted(alpha)

    # Lot's of checks already inside quantile_CI
    LB1, UB1 = qt.quantile_CI(X, q, alpha1)  # This CI should be larger
    LB2, UB2 = qt.quantile_CI(X, q, alpha2)
    assert LB1 <= LB2
    assert UB1 >= UB2
Esempio n. 2
0
def test_quantile_CI_monotone_q(args):
    X, q, alpha = args

    q1, q2 = sorted(q)

    # Lot's of checks already inside quantile_CI
    LB1, UB1 = qt.quantile_CI(X, q1, alpha)
    LB2, UB2 = qt.quantile_CI(X, q2, alpha)
    assert LB1 <= LB2
    assert UB1 <= UB2
Esempio n. 3
0
def test_quantile_CI_monotone_x(args):
    X, q, alpha = args

    assume(len(X) >= 1)

    LB1, UB1 = qt.quantile_CI(X, q, alpha)

    X2 = np.copy(X)
    X2[0] = -np.inf
    LB2, UB2 = qt.quantile_CI(X2, q, alpha)
    assert LB1 >= LB2
    assert UB1 >= UB2

    X2 = np.copy(X)
    X2[0] = np.inf
    LB2, UB2 = qt.quantile_CI(X2, q, alpha)
    assert LB1 <= LB2
    assert UB1 <= UB2
Esempio n. 4
0
def test_quantile_and_CI(args):
    X, q, alpha = args

    estimate0, LB0, UB0 = qt.quantile_and_CI(X, q, alpha)
    assert LB0 <= estimate0
    assert estimate0 <= UB0

    # Recompute without using _ internal funcs
    LB, UB = qt.quantile_CI(X, q, alpha=alpha)
    estimate = qt.quantile(X, q)

    assert estimate0 == estimate
    assert LB0 == LB
    assert UB0 == UB
Esempio n. 5
0
def mc_test_quantile_CI(mc_runs=1000,
                        n=2000,
                        q=0.5,
                        alpha=0.05,
                        random=np.random):
    q0 = ss.norm.ppf(q)

    X = random.randn(mc_runs, n)
    R = np.array([qt.quantile_CI(xx, q) for xx in X])
    LB, UB = R[:, 0], R[:, 1]

    n_pass = np.sum((LB <= q0) & (q0 <= UB))
    # This is only a one-sided test
    pval = ss.binom.cdf(n_pass, mc_runs, 1 - alpha)
    return pval
Esempio n. 6
0
def test_min_quantile_CI(args):
    X, q, m, alpha = args

    estimate0, LB0, UB0 = qt.min_quantile_CI(X, q, m, alpha)
    assert LB0 <= estimate0
    assert estimate0 <= UB0

    # Recompute without using _ internal funcs
    q = 1.0 - (1.0 - q)**(1.0 / m)
    LB, UB = qt.quantile_CI(X, q, alpha=alpha)
    estimate = qt.quantile(X, q)

    assert estimate0 == estimate
    assert LB0 == LB
    assert UB0 == UB
Esempio n. 7
0
def test_quantile_CI(args):
    X, q, alpha = args

    idx_q = qt._quantile(len(X), q)
    idx_l, idx_u = qt._quantile_CI(len(X), q, alpha)
    assert idx_l <= idx_q
    assert idx_q <= idx_u

    # Lot's of checks already inside quantile_CI
    LB, UB = qt.quantile_CI(X, q, alpha)
    assert LB <= UB

    estimate = qt.quantile(X, q)
    assert LB <= estimate
    assert estimate <= UB