Skip to content
Prev 140423 / 398506 Next

generate random numbers subject to constraints

On 26-Mar-08 21:26:59, Ala' Jaouni wrote:
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.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 26-Mar-08                                       Time: 22:06:38
------------------------------ XFMail ------------------------------