[R] generate random numbers that sum up to 1
Alberto Monteiro
albmont at centroin.com.br
Mon Oct 16 21:51:17 CEST 2006
I found another method to generate this, in the Borg of all Wisdom:
http://en.wikipedia.org/wiki/Simplex
Alberto Monteiro
---
Section Random Sampling:
The second method [[the first method is based on the Dirichlet
distribution -- avfm]] to generate a random point on the unit
simplex is based on the order statistics of the uniform distribution
on the unit interval, and was popularized by Horst Kraemer. The
algorithm is as follows:
Set p0 = 0 and pK=1.
Generate K-1 uniform random draws pi from the open interval (0,1).
Sort into ascending order the K+1 points p0, ..., pK.
The K coordinates t1, ..., tK of the final point on the unit
simplex are given by ti=pi-pi-1.
It has been pointed out by Smith and Tromble that the second
method is technically only valid if none of the differences
pi-p(i-1) are equal to zero. In practice, it is sufficient
to merely re-run the algorithm to generate a new set of
points if this happens.
More information about the R-help
mailing list