[R] generate random numbers subject to constraints

Naji Nassar nassar at noos.fr
Thu Mar 27 14:35:14 CET 2008


Hi all


One suggestion, tranforme the x

0<x1<1.... Tranforme x1=exp(u1)/(exp(u1)+exp(u2)+exp(u3)+1)
0<x2<1.... Tranforme x2=exp(u2)/(exp(u1)+exp(u2)+exp(u3)+1)
0<x3<1.... Tranforme x3=exp(u3)/(exp(u1)+exp(u2)+exp(u3)+1)
0<x4<1.... Tranforme x4=      1/(exp(u1)+exp(u2)+exp(u3)+1)

x1+x2+x3+x4=1

Now solve :
Aexp(u1)+bexp(u2)+cexp(u3)+d=n(exp(u1)+exp(u2)+exp(u3)+1)

(c-n)exp(u3)=(n-a)exp(u1)+(n-b)exp(u2)+n-d
u3=ln((n-a)/(c-n)exp(u1)+(n-b)/(c-n)exp(u2)+(n-d)/(c-n)) (u3 expression)

Generate u1
Generate u2 bounded so the ln term should be positive
    (n-a)/(c-n)exp(u1)+(n-b)/(c-n)exp(u2)+(n-d)/(c-n)>0
    u > or < ln()
(u1 & u2 are not independant)
Compute u3 given the above formula

Generate the x


Hope this help
Naji



Le 26/03/08 22:41, « Ala' Jaouni » <ajaouni at gmail.com> a écrit :

> X1,X2,X3,X4 should have independent distributions. They should be
> between 0 and 1 and all add up to 1. Is this still possible with
> Robert's method?
> 
> Thanks
> 
> ______________________________________________
> 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.



More information about the R-help mailing list