Re: [R] generate random numbers subject to constraints

From: Naji Nassar <nassar_at_noos.fr>
Date: Thu, 27 Mar 2008 14:35:14 +0100

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.



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. Received on Thu 27 Mar 2008 - 13:59:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Mar 2008 - 14:00:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive