QuantileConfidence

class QuantileConfidence(*args)

Estimate confidence intervals of a quantile.

Refer to Estimation of a quantile bound.

Warning

This class is experimental and likely to be modified in future releases. To use it, import the openturns.experimental submodule.

Parameters:
alphafloat

Quantile level

betafloat, optional

Confidence level. Default value is 0.95

Methods

computeAsymptoticBilateralConfidenceInterval(sample)

Evaluate asymptotic bilateral bounds of a quantile.

computeAsymptoticBilateralRank(size)

Evaluate the asymptotic bilateral rank of a quantile.

computeBilateralConfidenceInterval(sample)

Evaluate a bilateral confidence interval of a quantile.

computeBilateralMinimumSampleSize()

Evaluate the minimum size of the sample for the bilateral case.

computeBilateralRank(size)

Evaluate the bilateral rank of a quantile.

computeUnilateralConfidenceInterval(sample)

Evaluate an unilateral confidence interval of a quantile.

computeUnilateralMinimumSampleSize([rank, tail])

Evaluate the minimum sample size for the unilateral case.

computeUnilateralRank(size[, tail])

Evaluate an unilateral rank of a quantile.

getAlpha()

Quantile level accessor.

getBeta()

Confidence level accessor.

getClassName()

Accessor to the object's name.

getName()

Accessor to the object's name.

hasName()

Test if the object is named.

setAlpha(alpha)

Quantile level accessor.

setBeta(beta)

Confidence level accessor.

setName(name)

Accessor to the object's name.

Notes

This class estimates bounds of the quantile of level \alpha \in [0,1] of the random variable X with a confidence greater than \beta using a given order statistics.

Let x_{\alpha} be the unknown quantile of level \alpha of the random variable X of dimension 1. Let (X_1, \dots, X_\sampleSize) be a sample of independent and identically distributed variables according to X.

The bounds of the interval are computed from order statistics that we now introduce. Let X_{(k)} be the k -th order statistics of (X_1, \dots, X_\sampleSize) which means that X_{(k)} is the k -th maximum of (X_1, \dots, X_\sampleSize) for 1 \leq k \leq \sampleSize.

For example, X_{(1)} = \min (X_1, \dots, X_\sampleSize) is the minimum and X_{(\sampleSize)} = \max (X_1, \dots, X_\sampleSize) is the maximum.

We have:

X_{(1)} \leq X_{(2)} \leq \dots \leq X_{(\sampleSize)}

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> sample = ot.Gumbel().getSample(100)
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> ci = algo.computeUnilateralConfidenceInterval(sample)
__init__(*args)
computeAsymptoticBilateralConfidenceInterval(sample)

Evaluate asymptotic bilateral bounds of a quantile.

The asymptotic bounds are given by the order statistics:

[X_{(k_1)}, X_{(k_2)}]

so that:

\lim_{n \rightarrow \infty} \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}} \geq \beta

where the ranks 0 \leq k_1 \leq k_2 \leq n - 1 are given by computeAsymptoticBilateralRank().

Parameters:
sample2-d sequence of float

Sample of the variable X

Returns:
ciInterval

Quantile confidence interval

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> sample = ot.Gumbel().getSample(60)
>>> ci = algo.computeAsymptoticBilateralConfidenceInterval(sample)
computeAsymptoticBilateralRank(size)

Evaluate the asymptotic bilateral rank of a quantile.

This method computes two integers (k_1, k_2) such that:

\lim_{n \rightarrow \infty} \Prob{X_{(k_1)} \leq x_\alpha \leq X_{(k_2)}} = \beta, 0 \leq k_1 \leq k_2 \leq n - 1

In other words, the interval \left[X_{(k_1)}, X_{(k_2)} \right] is an asymptotic confidence interval for x_\alpha with asymptotic confidence \beta. The asymptotic bilateral ranks k_1, k_2 \in \llbracket 0, n - 1 \rrbracket are estimated from:

k_1 & = \left\lfloor n \alpha - \sqrt{n} z_{1-\beta/2} \sqrt{\alpha (1 - \alpha)} \right\rfloor - 1 \\
k_2 & = \left\lfloor n \alpha + \sqrt{n} z_{1-\beta/2} \sqrt{\alpha (1 - \alpha)} \right\rfloor - 1

with z_{1-\beta/2} the standard Gaussian quantile of order 1-\beta/2, see [delmas2006] proposition 12.2.13 page 257.

Parameters:
sizeint

Sample size

Returns:
ranksIndices of size 2

Pair of lower and upper ranks (k_1, k_2) with 0 \leq k_1 \leq k_2 \leq n-1.

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> k1, k2 = algo.computeAsymptoticBilateralRank(100)
>>> print(k1, k2)
0 8
computeBilateralConfidenceInterval(sample)

Evaluate a bilateral confidence interval of a quantile.

The confidence interval for the quantile of level \alpha is given by the order statistics:

[X_{(k_1)}, X_{(k_2)}]

so that:

\Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}} \geq \beta

where the ranks 0 \leq k_1 \leq k_2 \leq n - 1 are given by computeBilateralRank().

Parameters:
sample2-d sequence of float

Sample of the variable X

Returns:
ciInterval

Quantile confidence interval

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> sample = ot.Gumbel().getSample(60)
>>> ci = algo.computeBilateralConfidenceInterval(sample)
computeBilateralMinimumSampleSize()

Evaluate the minimum size of the sample for the bilateral case.

The minimal bilateral sample size is the smallest integer n such that:

\Prob{X_{(1)} \leq x_{\alpha} \leq X_{(n)}} \geq \beta.

In other words, this is the minimum sample size such that the interval \left[X_{(1)}, X_{(n)} \right] is a confidence interval of the quantile x_\alpha with confidence \beta. The solution of this problem is the minimum value of n such that:

1-\alpha^n-(1-\alpha)^n \geq \beta

The sample size n is searched inside the bounds given by the inequality:

\left\lfloor \frac{\log(1 - \beta)}{\log(\gamma)} \right\rfloor \leq n \leq \left\lceil \frac{\log(\frac{1-\beta}{2})}{\log(\gamma)} \right\rceil

where \gamma = \max(\alpha, 1- \alpha).

Returns:
sizeint

Minimum sample size n

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> size = algo.computeBilateralMinimumSampleSize()
>>> print(size)
59
computeBilateralRank(size)

Evaluate the bilateral rank of a quantile.

The bilateral ranks k_1, k_2 are the integers minimizing the probability:

\argmin_{0 \leq k_1 \leq k_2 \leq n - 1 \, | \, \Prob{k_1 < X \leq k_2} \geq \beta} \Prob{k_1 < X \leq k_2}

where X \sim \cB(n, \alpha) is the binomial distribution with parameters n and \alpha.

so that:

\Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}} \geq \beta.

These ranks exist only if:

1 - \alpha^n - (1-\alpha)^n \ge \beta.

Parameters:
sizeint

Sample size n

Returns:
ranksIndices of size 2

Pair of lower and upper ranks (k_1, k_2) such that 0 \leq k_1 \leq k_2 \leq n - 1.

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> k1, k2 = algo.computeBilateralRank(100)
>>> print((k1, k2))
(1, 10)
computeUnilateralConfidenceInterval(sample, tail=False)

Evaluate an unilateral confidence interval of a quantile.

The lower tail confidence interval is given by the order statistics:

[X_{(k_{low})}, +\infty[

so that:

\Prob{X_{(k_{low})} \leq x_{\alpha}} \geq \beta.

and the upper tail confidence interval is given by the order statistics:

]-\infty, X_{(k_{up})}]

so that:

\Prob{x_{\alpha} \leq X_{(k_{up})}} \geq \beta.

where the lower or upper ranks 0 \leq k_{low} \leq n - 1, 0 \leq k_{up} \leq n - 1 are given by computeUnilateralRank().

Parameters:
sample2-d sequence of float

Quantile level

tailbool, optional

True indicates the interval is bounded by a lower value. False indicates the interval is bounded by an upper value. Default value is False.

Returns:
ciInterval

Quantile confidence interval

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> sample = ot.Gumbel().getSample(100)
>>> ci = algo.computeUnilateralConfidenceInterval(sample)
computeUnilateralMinimumSampleSize(rank=0, tail=False)

Evaluate the minimum sample size for the unilateral case.

For the lower bound the minimal unilateral sample size is the smallest integer n such that:

\Prob{X_{(r)} \leq x_{\alpha}} \geq \beta.

For the upper bound the minimal unilateral sample size is the smallest integer n such that:

\Prob{x_{\alpha} \leq X_{(n-r-1)}} \geq \beta.

In the general case the minimum size of the sample is the smallest n such that:

F_{n,\alpha}(n-r-1) \geq \beta

where F_{n,\alpha} is the cumulative distribution function of the Binomial distribution with parameters n and \alpha.

When the rank r is zero the solution is analytical.

  • For the lower bound the minimum sample size is the integer that satisfies:

    1 - (1 - \alpha)^n \geq \beta

    which is given by:

    n_{low} = \left\lceil \frac{\log(1-\beta)}{\log(1-\alpha)} \right\rceil.

  • And for the upper bound the minimum sample size is the integer that satisfies:

    1 - \alpha^n \geq \beta

    which is given by:

    n_{up} = \left\lceil \frac{\log(1-\beta)}{\log(\alpha)} \right\rceil.

Parameters:
rankint, optional

Rank of the quantile. Default value is 0.

tailbool, optional

True indicates the interval is bounded by a lower value. False indicates the interval is bounded by an upper value. Default value is False.

Returns:
sizeint

Minimum sample size

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> size = algo.computeUnilateralMinimumSampleSize(0)
>>> print(size)
59
computeUnilateralRank(size, tail=False)

Evaluate an unilateral rank of a quantile.

The lower tail rank k_{low} is the largest integer k such that:

\Prob{X_{(k)} \leq x_{\alpha}} \geq \beta.

In other words, the interval \left[ X_{(k_{low})}, +\infty\right[ is a unilateral confidence interval for the quantile x_\alpha with confidence \beta.

It is given by:

k_{low} = \overline{F}^{-1}_{n, \alpha}(\beta)

where \overline{F}^{-1}_{n, \alpha} is the complementary quantile function of the binomial distribution with parameters n and \alpha.

The problem has a solution only if:

1 - (1 - \alpha)^n \geq \beta.

The upper tail rank k_{up} is the smallest integer k such that:

\Prob{x_{\alpha} \leq X_{(k)}} \geq \beta.

In other words, the interval \left]-\infty, X_{(k_{up})}\right] is a unilateral confidence interval for the quantile x_\alpha with confidence \beta. The solution is:

k_{up} = F^{-1}_{n, \alpha}(\beta)

where F^{-1}_{n, \alpha} is the quantile function of the cumulative distribution function of the binomial distribution with parameters n and \alpha. The problem has a solution only if:

1 - \alpha^n \geq \beta.

Parameters:
sizeint

Sample size

tailbool, optional

True indicates the interval is bounded by a lower value. False indicates the interval is bounded by an upper value. Default value is False.

Returns:
rankint

Rank k \in \{0, \hdots, n-1\}

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> alpha = 0.05
>>> beta = 0.95
>>> algo = otexp.QuantileConfidence(alpha, beta)
>>> rank = algo.computeUnilateralRank(100)
>>> print(rank)
9
getAlpha()

Quantile level accessor.

Returns:
alphafloat

Quantile level

getBeta()

Confidence level accessor.

Returns:
betafloat

Confidence level

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

setAlpha(alpha)

Quantile level accessor.

Parameters:
alphafloat

Quantile level

setBeta(beta)

Confidence level accessor.

Parameters:
betafloat

Confidence level

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

Examples using the class

Estimate quantile confidence intervals from data

Estimate quantile confidence intervals from data

Estimate a confidence interval of a quantile

Estimate a confidence interval of a quantile