[R] sampling from the uniform distribution over a convex hull

Adrian Baddeley adrian at maths.uwa.edu.au
Mon Mar 26 04:05:41 CEST 2007


Ranjan Maitra writes:

> Does anyone have a suggestion (or better still) code for sampling
> from the uniform distribution over the convex hull of a set of
> points?

This is implemented in library 'spatstat'.

If x and y are vectors of coordinates of your initial set of points,

   library(spatstat)

   W <- convexhull.xy(x, y)
   
   P <- runifpoint(42, W)

will compute the convex hull and generate 42 independent 
uniformly-distributed points in the convex hull.

The result can be plotted by 
    plot(P)
and the coordinates of the simulated points can be extracted
as P$x and P$y.

Adrian Baddeley



More information about the R-help mailing list