[R] how to generate a set of random numbers that sum to 1 with uniform distribution of elements
Albyn Jones
jones at reed.edu
Wed Nov 7 19:48:08 CET 2012
What uniform distribution do you want for the columns? The average
value of X_k given \sum X_i = 1 must be 1/n. If you start with
X_i ~ U(0,1), the result must be skewed.
If you generate X_i uniformly distributed on (0, 2/n), the conditional
distribution given the sum is 1 will be less skewed.
U <- matrix(runif(1000*100)/50,nrow=1000)
s <- apply(U,1,sum)
V <- U/s
qqplot(U[,1],V[,1])
albyn
On Wed, Nov 07, 2012 at 05:02:10AM -0800, Bärbel wrote:
> Hi,
> I am looking for a way to generate a matrix of random numbers in a way that
> each row of the matrix would sum to 1 and that the numbers in the columns of
> the matrix would have a uniform distribution. So far I have found several
> ways to create random numbers that would sum to 1, but then the distribution
> of the individual elements is more or less skewed - there are much more
> small numbers than larger ones.
> Any help and suggestions?
> - Bärbel
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-generate-a-set-of-random-numbers-that-sum-to-1-with-uniform-distribution-of-elements-tp4648695.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Albyn Jones
Reed College
jones at reed.edu
More information about the R-help
mailing list