0
$\begingroup$

I stumbled upon this post and I'm thinking if the problem can be generalized to continuous case.

In short, we generate $n$ random numbers, $X_1, X_2, ..., X_n$, which are uniformly distributed over the interval $[0, 1]$. The random numbers are i.i.d. What is $P(X_1 \le X_2 \le ... \le X_n)$?

  • 0
    If $X_{(1)}$ denotes the minimum of the $X_j$'s, and if $$X_{(i)} = \min(\{X_j \mid 1 \leq j \leq n\} \setminus \{X_{(k)} \mid k < i\})$$ (so $X_{(n)}$ is the maximum of the $X_j$'s), then the density function of $(X_{(1)}, \dots, X_{(n)})$ is given by $$f(x_1, ..., x_n) = \begin{cases}{ n! \prod_{i=1}^n f(x_i) \;\;\text{if } x_1<...2017-02-09
  • 0
    @Watson Can you explain how the PDF can be used to compute $P$?2017-02-09
  • 2
    Since the distributions are continuous, the probability that any two coincide is $0$. Hence the answer is just $\frac 1{n!}$.2017-02-09
  • 0
    Then $\int_{\Bbb R^n} f = 1 = n! P$. Actually we can find directly the desired probability: $$\int_{\{x_12017-02-09
  • 2
    To clarify: There are $n!$ possible orderings for the $\{X_i\}$. Each is equally probable, hence the answer is $\frac 1{n!}$. Phrased differently, the probability that $X_1$ is the least is $\frac 1n$. conditioned on that, the probability that $X_2$ is the second least is then $\frac 1{n-1}$, and so on.2017-02-09
  • 0
    The answer $1/n!$ is given in the _link_. There is no issue of sampling with replacement for your continuous version of the problem.2017-02-10

2 Answers 2

2

From the comments, it is clear that this problem is easily solved by combinatorial methods, so no simulation is needed to get the solution. You do not discuss your reason for wanting a simulation. But it is easy to show a relevant simulation in R statistical software, as below:

m = 10^6;  n = 5;  y = numeric(m)
for (i in 1:m) {
   x = runif(n);  s = sort(x)
   y[i] = sum(x==s) }
mean(y == n);  1/factorial(n);  round(factorial(n)*table(y)/m)
## 0.008197     # sim 1/5!
## 0.008333333  # exact 1/5!
## y
##  0  1  2  3  5 
## 44 45 20 10  1 

Table entries divided by $5!$ are probabilities of various counts of 'fixed points'. For example, 1/5! is the probability that all five $X_i$ are in sort order, and $44/5!$ is the probability that none of the $X_i$ are in sort order. That is $X_1 \ne X_{(i)},$ for all $i$. Perhaps you can find combinatorial solutions for those values.

There are more elegant ways to write such a program in R, using special features of the R language, but this method with an explicit 'for-loop' should be accessible to people who do not use R.

2

A simulation can also be implemented trivially in Mathematica:

F[n_, m_] := 10^m/Length[Select[RandomVariate[
  UniformDistribution[{0, 1}], {10^m, n}], OrderedQ]]

This generates $10^m$ samples of $n$ random $\operatorname{Uniform}(0,1)$ variables and counts the number of samples that were generated in nondecreasing sequence. Then it calculates the reciprocal of the incidence, so F[n,m] should return an number close to $n!$, with the accuracy increasing as the exponent $m$ increases.

Programming note: OrderedQ is quite a bit faster than # == Sort[#] & especially when $n$ is large, since the latter explicitly sorts each sample and then compares it to the original order to see if it is in order, whereas the former can just check by comparing each successive element to the previous and failing upon the first detection of a member that is less than the previous.

  • 0
    Not familiar with Mathematica, but looks nice.2017-03-10
  • 0
    @BruceET R is probably much faster to use than *Mathematica*, but I'm not proficient at R programming. It's interesting to see the differences in programming paradigm.2017-03-10
  • 0
    A more sophisticated R program with a defined 'function' wrapped in the 'replicate' procedure, and less-klutzy options for matching, might run faster than Mathematica, but explicit 'for-loops' generally run relatively slowly in R.2017-03-10