# rmh.ppm

##### Simulate from a Fitted Point Process Model

Given a point process model fitted to data, generate a random simulation of the model, using the Metropolis-Hastings algorithm.

##### Usage

```
# S3 method for ppm
rmh(model, start=NULL,
control=default.rmhcontrol(model, w=w),
…,
w = NULL,
project=TRUE,
nsim=1, drop=TRUE, saveinfo=TRUE,
verbose=TRUE, new.coef=NULL)
```

##### Arguments

- model
A fitted point process model (object of class

`"ppm"`

, see`ppm.object`

) which it is desired to simulate. This fitted model is usually the result of a call to`ppm`

. See**Details**below.- start
Data determining the initial state of the Metropolis-Hastings algorithm. See

`rmhstart`

for description of these arguments. Defaults to`list(x.start=data.ppm(model))`

- control
Data controlling the iterative behaviour of the Metropolis-Hastings algorithm. See

`rmhcontrol`

for description of these arguments.- …
Further arguments passed to

`rmhcontrol`

, or to`rmh.default`

, or to covariate functions in the model.- w
Optional. Window in which the simulations should be generated. Default is the window of the original data.

- project
Logical flag indicating what to do if the fitted model is invalid (in the sense that the values of the fitted coefficients do not specify a valid point process). If

`project=TRUE`

the closest valid model will be simulated; if`project=FALSE`

an error will occur.- nsim
Number of simulated point patterns that should be generated.

- drop
Logical. If

`nsim=1`

and`drop=TRUE`

(the default), the result will be a point pattern, rather than a list containing a single point pattern.- saveinfo
Logical value indicating whether to save auxiliary information.

- verbose
Logical flag indicating whether to print progress reports.

- new.coef
New values for the canonical parameters of the model. A numeric vector of the same length as

`coef(model)`

.

##### Details

This function generates simulated realisations from a point
process model that has been fitted to point pattern data. It is
a method for the generic function `rmh`

for the
class `"ppm"`

of fitted point process models. To simulate
other kinds of point process models, see `rmh`

or `rmh.default`

.

The argument `model`

describes the fitted model. It must be
an object of class `"ppm"`

(see `ppm.object`

),
and will typically be the result of a call to the point process
model fitting function `ppm`

.

The current implementation enables simulation from any fitted model
involving the interactions
`AreaInter`

,
`DiggleGratton`

,
`DiggleGatesStibbard`

,
`Geyer`

,
`Hardcore`

,
`MultiStrauss`

,
`MultiStraussHard`

,
`PairPiece`

,
`Poisson`

,
`Strauss`

,
`StraussHard`

and `Softcore`

,
including nonstationary models. See the examples.

It is also possible to simulate *hybrids* of several such models.
See `Hybrid`

and the examples.

It is possible that the fitted coefficients of a point process model
may be ``illegal'', i.e. that there may not exist a
mathematically well-defined point process with the given parameter
values. For example, a Strauss process with interaction
parameter \(\gamma > 1\) does not exist,
but the model-fitting procedure used in `ppm`

will sometimes
produce values of \(\gamma\) greater than 1.
In such cases, if `project=FALSE`

then an error will occur,
while if `project=TRUE`

then `rmh.ppm`

will find
the nearest legal model and simulate
this model instead. (The nearest legal model is obtained by
projecting the vector of coefficients onto the set of
valid coefficient vectors. The result is usually the Poisson process
with the same fitted intensity.)

The arguments `start`

and `control`

are lists of
parameters determining the initial state and the iterative
behaviour, respectively, of the Metropolis-Hastings algorithm.

The argument `start`

is passed directly to `rmhstart`

.
See `rmhstart`

for details of the parameters of the
initial state, and their default values.

The argument `control`

is first passed to
`rmhcontrol`

. Then if any additional arguments `…`

are given, `update.rmhcontrol`

is called to update the
parameter values. See `rmhcontrol`

for details of
the iterative behaviour parameters, and `default.rmhcontrol`

for their default values.

Note that if you specify expansion of the simulation window
using the parameter `expand`

(so that the
model will be simulated on a window larger than the original data
window) then the model must be capable of extrapolation to this
larger window. This is usually not possible for models which
depend on external covariates, because the domain of a covariate image
is usually the same as the domain of the fitted model.

After extracting the relevant information from the fitted model
object `model`

, `rmh.ppm`

invokes the default
`rmh`

algorithm `rmh.default`

, unless the model
is Poisson. If the model is Poisson then the Metropolis-Hastings
algorithm is not needed, and the model is simulated directly, using
one of `rpoispp`

, `rmpoispp`

,
`rpoint`

or `rmpoint`

.

See `rmh.default`

for further information about the
implementation, or about the Metropolis-Hastings algorithm.

##### Value

A point pattern (an object of class `"ppp"`

; see
`ppp.object`

) or a list of point patterns.

##### Warnings

See Warnings in `rmh.default`

.

##### See Also

`simulate.ppm`

,
`rmh`

,
`rmhmodel`

,
`rmhcontrol`

,
`default.rmhcontrol`

,
`update.rmhcontrol`

,
`rmhstart`

,
`rmh.default`

,
`ppp.object`

,
`ppm`

,

Interactions:
`AreaInter`

,
`DiggleGratton`

,
`DiggleGatesStibbard`

,
`Geyer`

,
`Hardcore`

,
`Hybrid`

,
`MultiStrauss`

,
`MultiStraussHard`

,
`PairPiece`

,
`Poisson`

,
`Strauss`

,
`StraussHard`

,
`Softcore`

##### Examples

```
# NOT RUN {
live <- interactive()
op <- spatstat.options()
spatstat.options(rmh.nrep=1e5)
Nrep <- 1e5
X <- swedishpines
if(live) plot(X, main="Swedish Pines data")
# Poisson process
fit <- ppm(X, ~1, Poisson())
Xsim <- rmh(fit)
if(live) plot(Xsim, main="simulation from fitted Poisson model")
# Strauss process
fit <- ppm(X, ~1, Strauss(r=7))
Xsim <- rmh(fit)
if(live) plot(Xsim, main="simulation from fitted Strauss model")
# }
# NOT RUN {
# Strauss process simulated on a larger window
# then clipped to original window
Xsim <- rmh(fit, control=list(nrep=Nrep, expand=1.1, periodic=TRUE))
Xsim <- rmh(fit, nrep=Nrep, expand=2, periodic=TRUE)
# }
# NOT RUN {
# }
# NOT RUN {
X <- rSSI(0.05, 100)
# piecewise-constant pairwise interaction function
fit <- ppm(X, ~1, PairPiece(seq(0.02, 0.1, by=0.01)))
Xsim <- rmh(fit)
# }
# NOT RUN {
# marked point pattern
Y <- amacrine
# }
# NOT RUN {
# marked Poisson models
fit <- ppm(Y)
fit <- ppm(Y,~marks)
fit <- ppm(Y,~polynom(x,2))
fit <- ppm(Y,~marks+polynom(x,2))
fit <- ppm(Y,~marks*polynom(x,y,2))
Ysim <- rmh(fit)
# }
# NOT RUN {
# multitype Strauss models
MS <- MultiStrauss(radii=matrix(0.07, ncol=2, nrow=2),
types = levels(Y$marks))
# }
# NOT RUN {
fit <- ppm(Y ~marks, MS)
Ysim <- rmh(fit)
# }
# NOT RUN {
fit <- ppm(Y ~ marks*polynom(x,y,2), MS)
Ysim <- rmh(fit)
if(live) plot(Ysim, main="simulation from fitted inhomogeneous Multitype Strauss")
spatstat.options(op)
# }
# NOT RUN {
# Hybrid model
fit <- ppm(redwood, ~1, Hybrid(A=Strauss(0.02), B=Geyer(0.1, 2)))
Y <- rmh(fit)
# }
```

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