QuantileConfidence

class QuantileConfidence(*args)

Estimate confidence intervals of a quantile.

Refer to Exact quantile confidence interval based on order statistics.

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.

computeBilateralConfidenceIntervalWithCoverage(sample)

Evaluate a bilateral confidence interval of a quantile.

computeBilateralMinimumSampleSize()

Evaluate the minimum size of the sample for the bilateral min - max confidence interval.

computeBilateralRank(size)

Evaluate the ranks of a quantile bilateral bound.

computeUnilateralConfidenceInterval(sample)

Evaluate an unilateral confidence interval of a quantile.

computeUnilateralConfidenceIntervalWithCoverage(sample)

Evaluate an unilateral confidence interval of a quantile.

computeUnilateralMinimumSampleSize([rank, tail])

Evaluate the minimum sample size for the unilateral confidence interval.

computeUnilateralRank(size[, tail])

Evaluate the rank of a quantile lower bound.

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 order statistics.

Let x_{\alpha} be the unknown quantile of level \alpha of the random variable X of dimension 1. Let (X_0, \dots, X_{\sampleSize-1}) 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+1 -th order statistics of (X_0, \dots, X_{\sampleSize-1}) for 0 \leq k \leq \sampleSize -1. For example, X_{(0)} = \min (X_0, \dots, X_{\sampleSize-1}) and X_{(\sampleSize -1)} = \max (X_0, \dots, X_{\sampleSize-1}).

We have:

X_{(0)} \leq X_{(1)} \leq \dots \leq X_{(\sampleSize -1)}

Care: Python enumeration begins at 0 so that the mathematical X_{(k)} order statistics of the theoretical file Exact quantile confidence interval based on order statistics where 1 \leq k \leq n corresponds to the order statistics X_{(k-1)} given by the library with this class QuantileConfidence.

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, \quad 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)}]

where (k_1, k_2) are the ranks with 0 \leq k_1 \leq k_2 \leq n - 1 defined by:

\begin{array}{ll}
(k_1, k_2) = & \argmin \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}}\\
             & \mbox{s.t.} \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}} \geq \beta
\end{array}

The ranks (k_1, k_2) are given by computeBilateralRank().

The statistics values are evaluated from the given sample.

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)
computeBilateralConfidenceIntervalWithCoverage(sample)

Evaluate a bilateral confidence interval of a quantile.

Refer to computeBilateralConfidenceInterval()

Parameters:
sample2-d sequence of float

Sample of the variable X.

Returns:
ciInterval

Quantile confidence interval.

coveragefloat

The coverage is the value of \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}}. The coverage is guaranteed to be greater or equal to \beta.

Notes

Refer to computeBilateralConfidenceInterval(). In addition to the confidence interval, the method returns the supremum of \beta for the 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, coverage = algo.computeBilateralConfidenceIntervalWithCoverage(sample)
computeBilateralMinimumSampleSize()

Evaluate the minimum size of the sample for the bilateral min - max confidence interval.

The method determines the smallest sample size n so that:

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

In other words, the interval \left[X_{(0)}, X_{(n-1)} \right] is a bilateral confidence interval for the quantile x_\alpha with confidence \beta, where X_{(0)} = \min(X_1, \dots, X_{n-1}) and X_{(n-1)} = \max(X_1, \dots, X_{n-1}).

The statistics values are evaluated from the sample.

See Exact quantile confidence interval based on order statistics to get the conditions of the existence of a solution and the solution.

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 ranks of a quantile bilateral bound.

The ranks k_1, k_2 with 0 \leq k_1, k_2 \leq \sampleSize -1 are defined by:

\begin{array}{ll}
(k_1, k_2) = & \argmin \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}}\\
             & \mbox{s.t.} \Prob{X_{(k_1)} \leq x_{\alpha} \leq X_{(k_2)}} \geq \beta
\end{array}

In other words, the interval \left[ X_{(k_1)}, X_{(k_2)} \right[ is a bilateral confidence interval for the quantile x_\alpha with confidence \beta.

See Exact quantile confidence interval based on order statistics to get the conditions of the existence of a solution and the solution.

Parameters:
sizeint

Sample size \sampleSize.

Returns:
ranksIndices of size 2

Pair of lower and upper ranks (k_1, k_2).

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 bounded confidence interval is given by the order statistics:

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

where k_{low} is the largest rank with 0 \leq k_{low} \leq \sampleSize - 1 so that:

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

The upper bounded confidence interval :

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

where k_{up} is the smallest rank with 0 \leq k_{up} \leq \sampleSize - 1 so that:

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

The lower or upper ranks k_{low} and k_{up} are given by computeUnilateralRank().

The statistics values are evaluated from the given sample.

Parameters:
sample2-d sequence of float

Quantile level

lower_boundedbool, 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)
computeUnilateralConfidenceIntervalWithCoverage(sample, tail=False)

Evaluate an unilateral confidence interval of a quantile.

Refer to computeUnilateralConfidenceInterval()

Parameters:
sample2-d sequence of float

Quantile level

lower_boundedbool, 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.

coveragefloat

If lower_bounded is True, then the coverage is the value of \Prob{X_{(k_1)} \leq x_{\alpha} }). Otherwise, the coverage is the value of \Prob{x_{\alpha} \leq X_{(k_2)}}. In both cases, the coverage is guaranteed to be greater or equal to \beta.

Notes

Refer to computeUnilateralConfidenceInterval(). In addition to the confidence interval, the method returns the supremum of \beta for the 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, coverage = algo.computeUnilateralConfidenceIntervalWithCoverage(sample)
computeUnilateralMinimumSampleSize(rank=0, tail=False)

Evaluate the minimum sample size for the unilateral confidence interval.

The rank k \geq 0 is specified. The method computes the smallest sample size n so that:

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

in the case of a lower bound of the quantile of order \alpha, and:

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

in the case of an upper bound.

In other words, the interval \left] -\infty, X_{(k)} \right] or \left[ X_{(k)}, +\infty \right[ is a unilateral confidence interval for the quantile x_\alpha with confidence \beta. The statistics values are evaluated from the sample.

See Exact quantile confidence interval based on order statistics to get the conditions of the existence of a solution and the solution.

Parameters:
kint, optional, k \geq 0

Rank of the quantile.

Default value is 0.

lower_boundedbool, 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 n.

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 the rank of a quantile lower bound.

The lower rank k_{low} is the largest rank k with 0 \leq k \leq \sampleSize -1 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.

The upper rank k_{up} is the smallest rank k with 0 \leq k \leq \sampleSize -1 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.

See Exact quantile confidence interval based on order statistics to get the conditions of the existence of a solution and the solution for each case.

Parameters:
sizeint

Sample size

lower_boundedbool, 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.

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 chemical process data

Estimate quantile confidence intervals from chemical process data

Estimate quantile confidence intervals

Estimate quantile confidence intervals

Compare the distribution of quantile estimators

Compare the distribution of quantile estimators