RandVec | R Documentation |
This function generates an n by m array x, each of whose m columns contains n random values lying in the interval [a,b], subject to the condition that their sum be equal to s. The distribution of values is uniform in the sense that it has the conditional probability distribution of a uniform distribution over the whole n-cube, given that the sum of the x's is s.
The function uses the randfixedsum
algorithm, written by Roger Stafford and implemented in MatLab. For details, see http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum/content/randfixedsum.m
RandVec(a=0, b=1, s=1, n=9, m=1, Seed=sample(1:1000, size = 1))
a |
The function |
b |
The argument |
s |
The argument |
n |
The number of requested elements per column. Default |
m |
The number of requested columns. Default |
Seed |
The seed that is used. Default |
An object of class RandVec
with components,
RandVecOutput |
The randomly generated vectors. |
Wim Van der Elst, Ariel Alonso, & Geert Molenberghs
The function is an R adaptation of a matlab program written by Roger Stafford. For details on the original Matlab algorithm, see: http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum/content/randfixedsum.m
# generate two vectors with 10 values ranging between 0 and 1
# where each vector sums to 1
# (uniform distribution over the whole n-cube)
Vectors <- RandVec(a=0, b=1, s=1, n=10, m=2)
sum(Vectors$RandVecOutput[,1])
sum(Vectors$RandVecOutput[,2])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.