in bayesmark/quantiles.py [0:0]
def quantile_CI(X, q, alpha=0.05):
"""Calculate CI on `q` quantile from same `X` using nonparametric estimation from order statistics.
This will have alpha level of at most `alpha` due to the discrete nature of order statistics.
Parameters
----------
X : :class:`numpy:numpy.ndarray` of shape (n,)
Data for quantile estimation. Can be vectorized. Must be sortable data type (which is almost everything).
q : float
Quantile to compute, must be in (0, 1). Can be vectorized.
alpha : float
False positive rate we allow for CI, must be in (0, 1). Can be vectorized.
Returns
-------
LB : dtype of `X`, scalar
Lower end on CI
UB : dtype of `X`, scalar
Upper end on CI
"""
assert np.ndim(X) >= 1
# We could robustify things to allow the edge cases, but maybe later
assert np.all(0 < q) and np.all(q < 1)
assert np.all(0 < alpha) and np.all(alpha < 1)
# Currently don't support broadcasting both at same time
assert np.ndim(X) == 1 or (np.ndim(q) == 0 and np.ndim(alpha) == 0)
n = X.shape[-1]
idx_lower, idx_upper = _quantile_CI(n, q, alpha)
o_stats = order_stats(X)
LB, UB = o_stats[..., idx_lower], o_stats[..., idx_upper]
return LB, UB