Note
Go to the end to download the full example code.
Compute the joint distribution of order statistics¶
Context¶
In this example, we define the joint distribution of the order statistics
of a given distribution
.
We detail the following cases:
Case 1: The Min - Max order statistics,
Case 2: Two order statistics that bound the
-quantile of
with the confidence level
.
Let be a random variable and
be the random vector of all its order statistics of size
.
Let
be its PDF and
its CDF. Then the random vector
of its
order statistics is distributed as the random vector
where the
are the order statistics of the Uniform distribution over
:
Then the CDF of is defined by:
and its PDF (if defined) by:
Thus, to get the joint distribution of , we use the
JointDistribution
whose all marginals are
and whose core is a
UniformOrderStatistics
.
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv
import math as m
ot.ResourceMap.SetAsString("Contour-DefaultColorMapNorm", "rank")
# sphinx_gallery_thumbnail_number = 2
We create the joint distribution of the order statistics from the distribution of
and the size of the order statistics:
n = 100
dist = ot.Normal()
orderStat_dist = ot.JointDistribution([dist] * n, otexp.UniformOrderStatistics(n))
Case 1: The Min - Max order statistics¶
We extract the first and last marginals of the order statistics distribution:
min_max_dist = orderStat_dist.getMarginal([0, n - 1])
We search the mode of the joint distribution. To get it, we search the point that maximizes the
log-PDF of the distribution. We use a OptimizationProblem
.
optimPb = ot.OptimizationProblem(min_max_dist.getLogPDF())
optimPb.setMinimization(False)
optimPb.setBounds(min_max_dist.getRange())
algo = ot.Cobyla(optimPb)
algo.setStartingPoint(min_max_dist.getMean())
algo.run()
mode = algo.getResult().getOptimalPoint()
print("Mode of the (Min-Max) joint distribution : ", mode)
Mode of the (Min-Max) joint distribution : [-2.37445,2.37445]
We draw its PDF.
g = min_max_dist.drawPDF()
contour = g.getDrawable(0).getImplementation()
contour.buildDefaultLevels(50)
contour.setIsFilled(True)
g.setDrawable(0, contour)
mode_cloud = ot.Cloud([mode])
mode_cloud.setPointStyle("bullet")
mode_cloud.setColor("red")
mode_cloud.setLegend("mode")
g.add(mode_cloud)
g.setTitle(r"Joint PDF of $(X_{(1)}, X_{(n)})$")
g.setXTitle(r"$X_{(1)}$")
g.setYTitle(r"$X_{(n)}$")
view = otv.View(g)
Case 2: Two order statistics that bound the
-quantile with the confidence level
.¶
We want to bound the -quantile
of
with two particular order statisctics among the
ones.
We choose these order statisctics such that they bound
with a confidence level equal to
.
For example, we want to bound the quantile of order
with a confidence
.
It is possible to use some particular order statistics to bound : [delmas2006]
(see proposition 11.1.3) shows that if
and
are two indices defined by:
where is the quantile of order
of the normal
distribution with zero mean and unit variance, then we have:
It means that any realization of the joint distribution of , for :math`n` large enough,
forms an interval that contains
with a confidence equal to
.
alpha = 0.90
beta = 0.05
a_beta = ot.Normal().computeQuantile(1 - beta / 2)[0]
delta = m.sqrt(n * alpha * (1 - alpha)) * a_beta
i_n = int(n * alpha - delta)
j_n = int(n * alpha + delta)
print("Chosen order statistics (in, jn) = ", i_n, j_n)
Chosen order statistics (in, jn) = 84 95
Be careful that the indices of the order statistics begins at 0.
ic_beta_dist = orderStat_dist.getMarginal([i_n - 1, j_n - 1])
We search the mode of the joint distribution. To get it, we search the point that maximizes the
log-PDF of the distribution. We use a OptimizationProblem
.
optimPb = ot.OptimizationProblem(ic_beta_dist.getLogPDF())
optimPb.setMinimization(False)
optimPb.setBounds(ic_beta_dist.getRange())
algo = ot.Cobyla(optimPb)
algo.setStartingPoint([1.1, 2.1])
algo.run()
mode = algo.getResult().getOptimalPoint()
print("Mode of the joint distribution : ", mode)
Mode of the joint distribution : [0.973152,1.55025]
g = ic_beta_dist.drawPDF()
contour = g.getDrawable(0).getImplementation()
contour.buildDefaultLevels(50)
contour.setIsFilled(True)
g.setDrawable(0, contour)
mode_cloud = ot.Cloud([mode])
mode_cloud.setPointStyle("bullet")
mode_cloud.setColor("red")
mode_cloud.setLegend("mode")
g.add(mode_cloud)
g.setTitle(r"Joint PDF of $(X_{(i_n)}, X_{(j_n)})$")
g.setXTitle(r"$X_{(i_n)}$")
g.setYTitle(r"$X_{(j_n)}$")
view = otv.View(g)
Display all figures
otv.View.ShowAll()