# rmpoint

##### Generate N Random Multitype Points

Generate a random multitype point pattern with a fixed number of points, or a fixed number of points of each type.

##### Usage

```
rmpoint(n, f=1, fmax=NULL, win=unit.square(),
types, ptypes,
..., giveup=1000, verbose=FALSE)
```

##### Arguments

- n
- Number of marked points to generate. Either a single number specifying the total number of points, or a vector specifying the number of points of each type.
- f
- The probability density of the multitype points,
usually un-normalised.
Either a constant, a vector,
a function
`f(x,y,m, ...)`

, a pixel image, a list of functions`f(x,y,...)`

or a list of pixel images. - fmax
- An upper bound on the values of
`f`

. If missing, this number will be estimated. - win
- Window in which to simulate the pattern.
Ignored if
`f`

is a pixel image or list of pixel images. - types
- All the possible types for the multitype pattern.
- ptypes
- Optional vector of probabilities for each type.
- ...
- Arguments passed to
`f`

if it is a function. - giveup
- Number of attempts in the rejection method after which the algorithm should stop trying to generate new points.
- verbose
- Flag indicating whether to report details of performance of the simulation algorithm.

##### Details

This function generates random multitype point patterns
consisting of a fixed number of points.
Three different models are available:
[object Object],[object Object],[object Object]
Note that the density `f`

is normalised in different ways
in Model I and Models II and III. In Model I the normalised
joint density is $g(x,y,m)=f(x,y,m)/Z$ where
$$Z = \sum_m \int\int \lambda(x,y,m) {\rm d}x \, {\rm d}y$$
while in Models II and III the normalised conditional density
is $g(x,y\mid m) = f(x,y,m)/Z_m$
where
$$Z_m = \int\int \lambda(x,y,m) {\rm d}x \, {\rm d}y.$$
In Model I, the marginal distribution of types
is $p_m = Z_m/Z$.
The unnormalised density `f`

may be specified
in any of the following ways.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The implementation uses the rejection method.
For Model I, `rmpoispp`

is called repeatedly
until `n`

points have been generated.
It gives up after `giveup`

calls
if there are still fewer than `n`

points.
For Model II, the types are first generated according to
`ptypes`

, then
the locations of the points of each type
are generated using `rpoint`

.
For Model III, the locations of the points of each type
are generated using `rpoint`

.

##### Value

- The simulated point pattern (an object of class
`"ppp"`

).

##### See Also

##### Examples

```
abc <- c("a","b","c")
##### Model I
rmpoint(25, types=abc)
rmpoint(25, 1, types=abc)
# 25 points, equal probability for each type, uniformly distributed locations
rmpoint(25, function(x,y,m) {rep(1, length(x))}, types=abc)
# same as above
rmpoint(25, list(function(x,y){rep(1, length(x))},
function(x,y){rep(1, length(x))},
function(x,y){rep(1, length(x))}),
types=abc)
# same as above
rmpoint(25, function(x,y,m) { x }, types=abc)
# 25 points, equal probability for each type,
# locations nonuniform with density proportional to x
rmpoint(25, function(x,y,m) { ifelse(m == "a", 1, x) }, types=abc)
rmpoint(25, list(function(x,y) { rep(1, length(x)) },
function(x,y) { x },
function(x,y) { x }),
types=abc)
# 25 points, UNEQUAL probabilities for each type,
# type "a" points uniformly distributed,
# type "b" and "c" points nonuniformly distributed.
##### Model II
rmpoint(25, 1, types=abc, ptypes=rep(1,3)/3)
rmpoint(25, 1, types=abc, ptypes=rep(1,3))
# 25 points, equal probability for each type,
# uniformly distributed locations
rmpoint(25, function(x,y,m) {rep(1, length(x))}, types=abc, ptypes=rep(1,3))
# same as above
rmpoint(25, list(function(x,y){rep(1, length(x))},
function(x,y){rep(1, length(x))},
function(x,y){rep(1, length(x))}),
types=abc, ptypes=rep(1,3))
# same as above
rmpoint(25, function(x,y,m) { x }, types=abc, ptypes=rep(1,3))
# 25 points, equal probability for each type,
# locations nonuniform with density proportional to x
rmpoint(25, function(x,y,m) { ifelse(m == "a", 1, x) }, types=abc, ptypes=rep(1,3))
# 25 points, EQUAL probabilities for each type,
# type "a" points uniformly distributed,
# type "b" and "c" points nonuniformly distributed.
###### Model III
rmpoint(c(12, 8, 4), 1, types=abc)
# 12 points of type "a",
# 8 points of type "b",
# 4 points of type "c",
# each uniformly distributed
rmpoint(c(12, 8, 4), function(x,y,m) { ifelse(m=="a", 1, x)}, types=abc)
rmpoint(c(12, 8, 4), list(function(x,y) { rep(1, length(x)) },
function(x,y) { x },
function(x,y) { x }),
types=abc)
# 12 points of type "a", uniformly distributed
# 8 points of type "b", nonuniform
# 4 points of type "c", nonuniform
#########
## Randomising an existing point pattern:
data(demopat)
X <- demopat
# same numbers of points of each type, uniform random locations (Model III)
rmpoint(table(X$marks), 1, types=levels(X$marks), win=X$window)
# same total number of points, distribution of types estimated from X,
# uniform random locations (Model II)
rmpoint(X$n, 1, types=levels(X$marks), win=X$window,
ptypes=table(X$marks))
```

*Documentation reproduced from package spatstat, version 1.20-1, License: GPL (>= 2)*