runifpoint {spatstat.random} | R Documentation |
Generate N Uniform Random Points
Description
Generate a random point pattern
containing n
independent uniform random points.
Usage
runifpoint(n, win=owin(c(0,1),c(0,1)), giveup=1000, warn=TRUE, ...,
nsim=1, drop=TRUE, ex=NULL)
Arguments
n |
Number of points. |
win |
Window in which to simulate the pattern.
An object of class |
giveup |
Number of attempts in the rejection method after which the algorithm should stop trying to generate new points. |
warn |
Logical. Whether to issue a warning if |
... |
Ignored. |
nsim |
Number of simulated realisations to be generated. |
drop |
Logical. If |
ex |
Optional. A point pattern to use as the example.
If |
Details
This function generates n
independent random points,
uniformly distributed in the window win
.
(For nonuniform distributions, see rpoint
.)
The algorithm depends on the type of window, as follows:
-
If
win
is a rectangle thenn
independent random points, uniformly distributed in the rectangle, are generated by assigning uniform random values to their cartesian coordinates. -
If
win
is a binary image mask, then a random sequence of pixels is selected (usingsample
) with equal probabilities. Then for each pixel in the sequence we generate a uniformly distributed random point in that pixel. -
If
win
is a polygonal window, the algorithm uses the rejection method. It finds a rectangle enclosing the window, generates points in this rectangle, and tests whether they fall in the desired window. It gives up whengiveup * n
tests have been performed without yieldingn
successes.
The algorithm for binary image masks is faster than the rejection method but involves discretisation.
If warn=TRUE
(the default), a warning will be issued if n
is very large.
The threshold is spatstat.options("huge.npoints")
.
This warning has no consequences,
but it helps to trap a number of common errors.
Value
A point pattern (an object of class "ppp"
)
or a list of point patterns.
Tessellation
The argument win
may be a tessellation
(object of class "tess"
, see tess
).
Then the specified number of points n
will be randomly generated
inside each tile of the tessellation. The argument n
may be
either a single integer, or an integer vector specifying the number
of points to be generated in each individual tile. The result will
be a point pattern in the window as.owin(win)
.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au and Rolf Turner rolfturner@posteo.net
See Also
ppp.object
,
owin.object
,
rpoispp
,
rpoint
Examples
# 100 random points in the unit square
pp <- runifpoint(100)
# irregular window
letterR
# polygonal
pp <- runifpoint(100, letterR)
# binary image mask
pp <- runifpoint(100, as.mask(letterR))
# randomising an existing point pattern
runifpoint(npoints(cells), win=Window(cells))
runifpoint(ex=cells)
# tessellation
A <- quadrats(unit.square(), 2, 3)
# different numbers of points in each cell
X <- runifpoint(1:6, A)