Dear all, I would like to know if there is a simple way to generate random numbers with the constrain that they sum up to one. I am new using R... Thanks in advance, N?ria _________________________________________________________________ Acepta el reto MSN Premium: Correos m?s divertidos con fotos y textos incre?bles en MSN Premium. Desc?rgalo y pru?balo 2 meses gratis.
N?ria Mart?nez napsal(a):> Dear all, > > I would like to know if there is a simple way to generate random numbers > with the constrain that they sum up to one. I am new using R... > > Thanks in advance, > > N?riaYou need to specify what 'random' means. If you have any numbers, you can always make them add-up to 1: x <- rnorm(100) #runif(100), rpois(100) etc. x <- x/sum(x) sum(x) Petr -- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
N?ria Mart?nez wrote:> Dear all, > > I would like to know if there is a simple way to generate random numbers > with the constrain that they sum up to one. I am new using R... >The easiest way is to generate them by whatever method and divide by their sum. e.g. as (s<-rexp(100))/sum(s) Are there other constraints, you need the numbers to satisfy? Obviously, they can't be independent. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907