Re: [R] generate random numbers subject to constraints
On Thu, 27 Mar 2008, Robert A LaBudde wrote: > At 05:06 PM 3/26/2008, Ted Harding wrote: >> On 26-Mar-08 21:26:59, Ala' Jaouni wrote: >>> 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 >> >> I don't think so. A whileago you wrote >> "The numbers should be uniformly distributed" (but in the >> context of an example where you had 5 variable; now you >> are back to 4 variables). Let's take the 4-case first. >> >> The two linear constraints confine the point (X1,X2,X3,X4) >> to a triangular region within the 4-dimensional unit cube. >> Say it has vertices A, B, C. >> You could then start by generating points uniformly distributed >> over a specific triangle in 2 dimentions, say the one with >> vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. >> >> Then you need to find a linear transformation which will >> map this triangle (A0,B0,C0) onto the triangle (A,B,C). >> Then the points you have sampled in (A0,B0,C0) will map >> into points which are uniformly distributed over the >> triangle (A,B,C). >> >> More generally, you will be seeking to generate points >> uniformly distributed over a simplex. >> >> For example, the case (your earlier post) of 5 points >> with 2 linear constraints requires a tetrahedron with >> vertices (A,B,C,D) in 5 dimensions whose coordinates you >> will have to find. Then take an "easy" tetrahedron with >> vertices (A0,B0,C0,D0) and sample uniformly within this. >> Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) >> and apply this to the sampled points. >> >> This raises a general question: Does anyone know of >> an R function to sample uniformly in the interior >> of a general (k-r)-dimensional simplex embedded in >> k dimensions, with (k+1) given vertices? >> > > The method of "rejection": > > 1. Generate numbers randomly in the hypercube. > 2. Test to see if the point falls within the prescribed area. > 3. Accept the point if it does. > 4. Repeat if it doesn't. > > Efficiency depends upon the ratio of volumes involved. The ratio is zero. The subspace of the solution has lower dimension than the space you are sampling from. So you will repeat '4' forever. (Up to machine accuracy, of course.) And as I pointed out in my response to Ala' Jaouni, the 'solution' may lie in the null space. When it does not it will be a point, a line segment, a piece of a plane, or a 3 dimensional simplex. Chuck > > > > Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [EMAIL PROTECTED] > Least Cost Formulations, Ltd.URL: http://lcfltd.com/ > 824 Timberlake Drive Tel: 757-467-0954 > Virginia Beach, VA 23464-3239Fax: 757-467-2947 > > "Vere scire est per causas scire" > > __ > R-help@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. > Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@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.
Re: [R] generate random numbers subject to constraints
Hi all One suggestion, tranforme the x 00 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 » <[EMAIL PROTECTED]> 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@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@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.
Re: [R] generate random numbers subject to constraints
At 05:06 PM 3/26/2008, Ted Harding wrote: >On 26-Mar-08 21:26:59, Ala' Jaouni wrote: > > 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 > >I don't think so. A whileago you wrote >"The numbers should be uniformly distributed" (but in the >context of an example where you had 5 variable; now you >are back to 4 variables). Let's take the 4-case first. > >The two linear constraints confine the point (X1,X2,X3,X4) >to a triangular region within the 4-dimensional unit cube. >Say it has vertices A, B, C. >You could then start by generating points uniformly distributed >over a specific triangle in 2 dimentions, say the one with >vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. > >Then you need to find a linear transformation which will >map this triangle (A0,B0,C0) onto the triangle (A,B,C). >Then the points you have sampled in (A0,B0,C0) will map >into points which are uniformly distributed over the >triangle (A,B,C). > >More generally, you will be seeking to generate points >uniformly distributed over a simplex. > >For example, the case (your earlier post) of 5 points >with 2 linear constraints requires a tetrahedron with >vertices (A,B,C,D) in 5 dimensions whose coordinates you >will have to find. Then take an "easy" tetrahedron with >vertices (A0,B0,C0,D0) and sample uniformly within this. >Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) >and apply this to the sampled points. > >This raises a general question: Does anyone know of >an R function to sample uniformly in the interior >of a general (k-r)-dimensional simplex embedded in >k dimensions, with (k+1) given vertices? > The method of "rejection": 1. Generate numbers randomly in the hypercube. 2. Test to see if the point falls within the prescribed area. 3. Accept the point if it does. 4. Repeat if it doesn't. Efficiency depends upon the ratio of volumes involved. Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [EMAIL PROTECTED] Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 "Vere scire est per causas scire" __ R-help@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.
Re: [R] generate random numbers subject to constraints
Ala' Jaouni gmail.com> writes: > > 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? > NO. If they add to 1 they are not independent. As Ted remarked, the constraints define two simplexes and the solution you seek lies in their intersection. However, depending on the choices of a, b, c, d, and n in a*X1+b*X2+c*X3+d*X4=n, there may not be a solution that satisfies your constraints (no intersection between the two simplexes - as when ahttps://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.
Re: [R] generate random numbers subject to constraints
OOPS! A mistake below. I should have written: This raises a general question: Does anyone know of an R function to sample uniformly in the interior of a general (k-r)-dimensional simplex embedded in k dimensions, with (k-r+1) given vertices? On 26-Mar-08 22:06:54, Ted Harding wrote: > On 26-Mar-08 21:26:59, Ala' Jaouni wrote: >> 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 > > I don't think so. A whileago you wrote > "The numbers should be uniformly distributed" (but in the > context of an example where you had 5 variable; now you > are back to 4 variables). Let's take the 4-case first. > > The two linear constraints confine the point (X1,X2,X3,X4) > to a triangular region within the 4-dimensional unit cube. > Say it has vertices A, B, C. > You could then start by generating points uniformly distributed > over a specific triangle in 2 dimentions, say the one with > vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. > > Then you need to find a linear transformation which will > map this triangle (A0,B0,C0) onto the triangle (A,B,C). > Then the points you have sampled in (A0,B0,C0) will map > into points which are uniformly distributed over the > triangle (A,B,C). > > More generally, you will be seeking to generate points > uniformly distributed over a simplex. > > For example, the case (your earlier post) of 5 points > with 2 linear constraints requires a tetrahedron with > vertices (A,B,C,D) in 5 dimensions whose coordinates you > will have to find. Then take an "easy" tetrahedron with > vertices (A0,B0,C0,D0) and sample uniformly within this. > Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) > and apply this to the sampled points. > > This raises a general question: Does anyone know of > an R function to sample uniformly in the interior > of a general (k-r)-dimensional simplex embedded in > k dimensions, with (k+1) given vertices? > > Best wishes to all, > Ted. > > >> On Wed, Mar 26, 2008 at 12:52 PM, Ted Harding >> <[EMAIL PROTECTED]> wrote: >>> On 26-Mar-08 20:13:50, Robert A LaBudde wrote: >>> > At 01:13 PM 3/26/2008, Ala' Jaouni wrote: >>> >>I am trying to generate a set of random numbers that fulfill >>> >>the following constraints: >>> >> >>> >>X1 + X2 + X3 + X4 = 1 >>> >> >>> >>aX1 + bX2 + cX3 + dX4 = n >>> >> >>> >>where a, b, c, d, and n are known. >>> >> >>> >>Any function to do this? >>> > >>> > 1. Generate random variates for X1, X2, based upon whatever >>> > unspecified distribution you wish. >>> > >>> > 2. Solve the two equations for X3 and X4. >>> >>> The trouble is that the original problem is not well >>> specified. Your suggestion, Robert, gives a solution >>> to one version of the problem -- enabling Ala' Jaouni >>> to say "I have generated 4 random numbers X1,X2,X3,X4 >>> such that X1 and X2 have specified distributions, >>> and X1,X2,X3,X4 satisfy the two equations ... ". >>> >>> However, suppose the real problem was: let X2,X2,X3,X4 >>> have independent distributions F1,F2,F3,F4. Now sample >>> X1,X2,X3,X4 conditional on the two equations (i.e. from >>> the coditional density). That is a different problem. >>> >>> As a slightly simpler example, suppose we have just X1,X2,X3 >>> and they are independently uniform on (0,1). Now sample >>> from the conditional distribution, conditional on >>> X1 + X2 + X3 = 1. >>> >>> The result is a random point uniformly distributed on the >>> planar triangle whose vertices are at (1,0,0),(0,1,0),(0,0,1). >>> >>> Then none of X1,X2,X3 is uniformly distributed (in fact >>> the marginal density of each is 2*(1-x)). >>> >>> However, your solution would work from either point of >>> view if the distributions were Normal. >>> >>> If X1,X2,X3,X4 were neither Normally nor uniformly >>> distributed, then finding or simulating the conditional >>> distribution would in general be difficult. >>> >>> Ala' Jaouni needs to tell us whether what he precisely >>> wants is as you stated the problem, Robert, or whether >>> he wants a conditional distribution for given distributions >>> if X1,X2,X3,X4, or whether he wants something else. >>> >>> Best wishes to all, >>> Ted. >>> >>> >>> E-Mail: (Ted Harding) <[EMAIL PROTECTED]> >>> Fax-to-email: +44 (0)870 094 0861 >>> Date: 26-Mar-08 Time: 19:52:16 >>> -- XFMail -- >>> >> >> __ >> R-help@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. > > > E-Mail: (Ted Harding) <[EM
Re: [R] generate random numbers subject to constraints
On 26-Mar-08 21:26:59, Ala' Jaouni wrote: > 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 I don't think so. A whileago you wrote "The numbers should be uniformly distributed" (but in the context of an example where you had 5 variable; now you are back to 4 variables). Let's take the 4-case first. The two linear constraints confine the point (X1,X2,X3,X4) to a triangular region within the 4-dimensional unit cube. Say it has vertices A, B, C. You could then start by generating points uniformly distributed over a specific triangle in 2 dimentions, say the one with vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. Then you need to find a linear transformation which will map this triangle (A0,B0,C0) onto the triangle (A,B,C). Then the points you have sampled in (A0,B0,C0) will map into points which are uniformly distributed over the triangle (A,B,C). More generally, you will be seeking to generate points uniformly distributed over a simplex. For example, the case (your earlier post) of 5 points with 2 linear constraints requires a tetrahedron with vertices (A,B,C,D) in 5 dimensions whose coordinates you will have to find. Then take an "easy" tetrahedron with vertices (A0,B0,C0,D0) and sample uniformly within this. Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) and apply this to the sampled points. This raises a general question: Does anyone know of an R function to sample uniformly in the interior of a general (k-r)-dimensional simplex embedded in k dimensions, with (k+1) given vertices? Best wishes to all, Ted. > On Wed, Mar 26, 2008 at 12:52 PM, Ted Harding > <[EMAIL PROTECTED]> wrote: >> On 26-Mar-08 20:13:50, Robert A LaBudde wrote: >> > At 01:13 PM 3/26/2008, Ala' Jaouni wrote: >> >>I am trying to generate a set of random numbers that fulfill >> >>the following constraints: >> >> >> >>X1 + X2 + X3 + X4 = 1 >> >> >> >>aX1 + bX2 + cX3 + dX4 = n >> >> >> >>where a, b, c, d, and n are known. >> >> >> >>Any function to do this? >> > >> > 1. Generate random variates for X1, X2, based upon whatever >> > unspecified distribution you wish. >> > >> > 2. Solve the two equations for X3 and X4. >> >> The trouble is that the original problem is not well >> specified. Your suggestion, Robert, gives a solution >> to one version of the problem -- enabling Ala' Jaouni >> to say "I have generated 4 random numbers X1,X2,X3,X4 >> such that X1 and X2 have specified distributions, >> and X1,X2,X3,X4 satisfy the two equations ... ". >> >> However, suppose the real problem was: let X2,X2,X3,X4 >> have independent distributions F1,F2,F3,F4. Now sample >> X1,X2,X3,X4 conditional on the two equations (i.e. from >> the coditional density). That is a different problem. >> >> As a slightly simpler example, suppose we have just X1,X2,X3 >> and they are independently uniform on (0,1). Now sample >> from the conditional distribution, conditional on >> X1 + X2 + X3 = 1. >> >> The result is a random point uniformly distributed on the >> planar triangle whose vertices are at (1,0,0),(0,1,0),(0,0,1). >> >> Then none of X1,X2,X3 is uniformly distributed (in fact >> the marginal density of each is 2*(1-x)). >> >> However, your solution would work from either point of >> view if the distributions were Normal. >> >> If X1,X2,X3,X4 were neither Normally nor uniformly >> distributed, then finding or simulating the conditional >> distribution would in general be difficult. >> >> Ala' Jaouni needs to tell us whether what he precisely >> wants is as you stated the problem, Robert, or whether >> he wants a conditional distribution for given distributions >> if X1,X2,X3,X4, or whether he wants something else. >> >> Best wishes to all, >> Ted. >> >> >> E-Mail: (Ted Harding) <[EMAIL PROTECTED]> >> Fax-to-email: +44 (0)870 094 0861 >> Date: 26-Mar-08 Time: 19:52:16 >> -- XFMail -- >> > > __ > R-help@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. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 26-Mar-08 Time: 22:06:38 -- XFMail -- __ R-help@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
Re: [R] generate random numbers subject to constraints
Ala' Jaouni wrote: > > I am trying to generate a set of random numbers that fulfill the > following constraints: > > X1 + X2 + X3 + X4 = 1 > > aX1 + bX2 + cX3 + dX4 = n > > where a, b, c, d, and n are known. > > Any function to do this? > You must give more information. How are those numbers distributed? Are they normal? Positive? If they can be anything, just generate X1, X2 and then compute X3, X4. Alberto Monteiro __ R-help@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.
Re: [R] generate random numbers subject to constraints
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@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.
Re: [R] generate random numbers subject to constraints
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 On Wed, Mar 26, 2008 at 12:52 PM, Ted Harding <[EMAIL PROTECTED]> wrote: > On 26-Mar-08 20:13:50, Robert A LaBudde wrote: > > At 01:13 PM 3/26/2008, Ala' Jaouni wrote: > >>I am trying to generate a set of random numbers that fulfill > >>the following constraints: > >> > >>X1 + X2 + X3 + X4 = 1 > >> > >>aX1 + bX2 + cX3 + dX4 = n > >> > >>where a, b, c, d, and n are known. > >> > >>Any function to do this? > > > > 1. Generate random variates for X1, X2, based upon whatever > > unspecified distribution you wish. > > > > 2. Solve the two equations for X3 and X4. > > The trouble is that the original problem is not well > specified. Your suggestion, Robert, gives a solution > to one version of the problem -- enabling Ala' Jaouni > to say "I have generated 4 random numbers X1,X2,X3,X4 > such that X1 and X2 have specified distributions, > and X1,X2,X3,X4 satisfy the two equations ... ". > > However, suppose the real problem was: let X2,X2,X3,X4 > have independent distributions F1,F2,F3,F4. Now sample > X1,X2,X3,X4 conditional on the two equations (i.e. from > the coditional density). That is a different problem. > > As a slightly simpler example, suppose we have just X1,X2,X3 > and they are independently uniform on (0,1). Now sample > from the conditional distribution, conditional on > X1 + X2 + X3 = 1. > > The result is a random point uniformly distributed on the > planar triangle whose vertices are at (1,0,0),(0,1,0),(0,0,1). > > Then none of X1,X2,X3 is uniformly distributed (in fact > the marginal density of each is 2*(1-x)). > > However, your solution would work from either point of > view if the distributions were Normal. > > If X1,X2,X3,X4 were neither Normally nor uniformly > distributed, then finding or simulating the conditional > distribution would in general be difficult. > > Ala' Jaouni needs to tell us whether what he precisely > wants is as you stated the problem, Robert, or whether > he wants a conditional distribution for given distributions > if X1,X2,X3,X4, or whether he wants something else. > > Best wishes to all, > Ted. > > > E-Mail: (Ted Harding) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 26-Mar-08 Time: 19:52:16 > -- XFMail -- > __ R-help@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.
Re: [R] generate random numbers subject to constraints
On 26-Mar-08 20:13:50, Robert A LaBudde wrote: > At 01:13 PM 3/26/2008, Ala' Jaouni wrote: >>I am trying to generate a set of random numbers that fulfill >>the following constraints: >> >>X1 + X2 + X3 + X4 = 1 >> >>aX1 + bX2 + cX3 + dX4 = n >> >>where a, b, c, d, and n are known. >> >>Any function to do this? > > 1. Generate random variates for X1, X2, based upon whatever > unspecified distribution you wish. > > 2. Solve the two equations for X3 and X4. The trouble is that the original problem is not well specified. Your suggestion, Robert, gives a solution to one version of the problem -- enabling Ala' Jaouni to say "I have generated 4 random numbers X1,X2,X3,X4 such that X1 and X2 have specified distributions, and X1,X2,X3,X4 satisfy the two equations ... ". However, suppose the real problem was: let X2,X2,X3,X4 have independent distributions F1,F2,F3,F4. Now sample X1,X2,X3,X4 conditional on the two equations (i.e. from the coditional density). That is a different problem. As a slightly simpler example, suppose we have just X1,X2,X3 and they are independently uniform on (0,1). Now sample from the conditional distribution, conditional on X1 + X2 + X3 = 1. The result is a random point uniformly distributed on the planar triangle whose vertices are at (1,0,0),(0,1,0),(0,0,1). Then none of X1,X2,X3 is uniformly distributed (in fact the marginal density of each is 2*(1-x)). However, your solution would work from either point of view if the distributions were Normal. If X1,X2,X3,X4 were neither Normally nor uniformly distributed, then finding or simulating the conditional distribution would in general be difficult. Ala' Jaouni needs to tell us whether what he precisely wants is as you stated the problem, Robert, or whether he wants a conditional distribution for given distributions if X1,X2,X3,X4, or whether he wants something else. Best wishes to all, Ted. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 26-Mar-08 Time: 19:52:16 -- XFMail -- __ R-help@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.
Re: [R] generate random numbers subject to constraints
On Wed, Mar 26, 2008 at 7:27 PM, Ala' Jaouni <[EMAIL PROTECTED]> wrote: > I failed to mention that the X values have to be positive and between 0 and > 1. Use Robert's method, and to do his step 1, use runif (?runif) to get random numbers from the uniform distribution between 0 and 1. Paul __ R-help@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.
Re: [R] generate random numbers subject to constraints
You have 4 random variables that satisfy 2 linear constraints, so you are trying to generate a point in a (4-2) = 2 dimensional linear (affine, in fact) subspace of R^4. If you don't have any further requirement for the distribution of the random points you want to generate, there are infinitely many ways of doing it. It would be a good idea if you could explain in some more detail what you want to do, so that we can give you relevant suggestions. Best, Giovanni > Date: Wed, 26 Mar 2008 11:28:28 -0700 > From: "Ala' Jaouni" <[EMAIL PROTECTED]> > Sender: [EMAIL PROTECTED] > Precedence: list > > I am trying to generate a set of random numbers that fulfill the > following constraints: > > X1 + X2 + X3 + X4 = 1 > > aX1 + bX2 + cX3 + dX4 = n > > where a, b, c, d, and n are known. > > Any function to do this? > > Thanks, > -Ala' > > __ > R-help@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. > > -- Giovanni Petris Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@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.
Re: [R] generate random numbers subject to constraints
Hi, I failed to mention that the X values have to be positive and between 0 and 1. e.g. 0.1812*X1 + 0.1871*X2 + 0.1847*X3 + 0.2745*X4 + 0.1304*X5 = 0.2 so one possible combination of X values can be: 0.319, 0.201, 0.084, 0.26, 0.136 another possible combination: 0.151, 0.253, 0.197, 0.256, 0.143 The numbers should be uniformly distributed. I might have misused the word random but I only need a subset of all possible solutions. -Ala' __ R-help@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.
Re: [R] generate random numbers subject to constraints
At 01:13 PM 3/26/2008, Ala' Jaouni wrote: >I am trying to generate a set of random numbers that fulfill the following >constraints: > >X1 + X2 + X3 + X4 = 1 > >aX1 + bX2 + cX3 + dX4 = n > >where a, b, c, d, and n are known. > >Any function to do this? 1. Generate random variates for X1, X2, based upon whatever unspecified distribution you wish. 2. Solve the two equations for X3 and X4. Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [EMAIL PROTECTED] Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 "Vere scire est per causas scire" __ R-help@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.