Adjacent Order-Statistic Gap Distributions
Problem statement
For this exercise, the random draws are supplied as a matrix samples. Each row contains ten finite values in [0,1].
For every row:
- Sort a copy in ascending order.
- Compute
gapA = sorted[4] - sorted[3], the gap between the fourth and fifth order statistics. - Compute
gapB = sorted[5] - sorted[4], the gap between the fifth and sixth order statistics.
Return a double[][] with two rows. The first row contains every gapA; the second contains every gapB. Preserve the input-row order, and do not mutate samples.
The returned arrays are the two empirical distributions. Visualization and hypothesis testing are follow-up discussion topics rather than additional judged outputs.
Function
adjacentGapDistributions(samples: double[][]) → double[][]Examples
Example 1
samples = [[0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]]return = [[0.1],[0.1]]The sorted row is unchanged. Both adjacent gaps around the fifth order statistic equal 0.1.
Example 2
samples = [[0.9,0.1,0.4,0.8,0.2,0.7,0.3,0.6,0.0,0.5],[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]]return = [[0.1,0.0],[0.1,0.0]]The first row sorts to tenths from 0.0 through 0.9. The all-equal row has zero gaps.
Example 3
samples = [[0.0,0.0,0.0,0.0,0.25,0.75,1.0,1.0,1.0,1.0]]return = [[0.25],[0.5]]The fourth value is 0.0, the fifth is 0.25, and the sixth is 0.75.
Constraints
1 <= samples.length <= 100000.samples[i].length == 10.- Every value is finite and lies in
[0,1]. - Return gaps in input-row order.
- Answers within
10^-9of the correct values are accepted.