spatstat (version 1.16-1)

rpoint: Generate N Random Points


Generate a random point pattern containing $n$ independent, identically distributed random points with any specified distribution.


rpoint(n, f, fmax=NULL, win=unit.square(), ..., giveup=1000, verbose=FALSE)


Number of points to generate.
The probability density of the points, possibly un-normalised. Either a constant, a function f(x,y,...), or a pixel image object.
An upper bound on the values of f. If missing, this number will be estimated.
Window in which to simulate the pattern. Ignored if f is a pixel image.
Arguments passed to the function f.
Number of attempts in the rejection method after which the algorithm should stop trying to generate new points.
Flag indicating whether to report details of performance of the simulation algorithm.


  • The simulated point pattern (an object of class "ppp").


This function generates n independent, identically distributed random points with common probability density proportional to f.

The argument f may be [object Object],[object Object],[object Object] The algorithm is as follows:

  • Iffis a constant, we invokerunifpoint.
  • Iffis a function, then we use the rejection method. Proposal points are generated from the uniform distribution. A proposal point$(x,y)$is accepted with probabilityf(x,y,...)/fmaxand otherwise rejected. The algorithm continues untilnpoints have been accepted. It gives up aftergiveup * nproposals if there are still fewer thannpoints.
  • Iffis a pixel image, then a random sequence of pixels is selected (usingsample) with probabilities proportional to the pixel values off. Then for each pixel in the sequence we generate a uniformly distributed random point in that pixel.
The algorithm for pixel images is more efficient than that for functions.

See Also

ppp.object, owin.object, runifpoint


Run this code
# 100 uniform random points in the unit square
 X <- rpoint(100)

 # 100 random points with probability density proportional to x^2 + y^2
 X <- rpoint(100, function(x,y) { x^2 + y^2}, 1)

 # `fmax' may be omitted
 X <- rpoint(100, function(x,y) { x^2 + y^2})

 # irregular window
 X <- rpoint(100, function(x,y) { x^2 + y^2}, win=letterR)

 # make a pixel image 
 Z <- setcov(letterR)
 # 100 points with density proportional to pixel values
 X <- rpoint(100, Z)

Run the code above in your browser using DataCamp Workspace