Reputation: 844
Suppose I want to make a vector of length N. My goal is to ensure that all the elements are approximately 1/N (but not all elements should be exactly 1/N) and the sum of the vector should equal to one. Is there a way to do this in R?
Upvotes: 0
Views: 42
Reputation: 84519
You can use a Dirichlet distribution, with large and equal parameters.
> library(bayesm)
> rdirichlet(c(100,100,100))
[,1]
[1,] 0.3360327
[2,] 0.3280179
[3,] 0.3359495
> rdirichlet(c(10000,10000,10000))
[,1]
[1,] 0.3311760
[2,] 0.3353209
[3,] 0.3335032
> rdirichlet(c(1000000,1000000,1000000))
[,1]
[1,] 0.3330997
[2,] 0.3334884
[3,] 0.3334119
Upvotes: 4