[R] spatstat package: Simulating from fitted Matern cluster process model fails

Rolf Turner r.turner at auckland.ac.nz
Sun Jul 6 23:56:49 CEST 2014



There appears to be a small bug in the code.  What is happening is that 
occasionally there are simulated points that lie inside your triangular 
window but do not lie inside any pixel of the image created from your 
"distorigin()" function.

This will be fixed in a future release of spatstat.  In the meantime I 
think you can work around the problem by using finer pixellations. For 
your example,

     spatstat.options(npixel=256)

seems to work.  For a real life example you might need to go with a 
larger value of npixel, e.g. 512.  (Powers of 2 are recommended although 
not required.)

cheers,

Rolf Turner

On 07/07/14 00:36, Philipp Hunziker wrote:
> Dear R-help list,
>
> I'm using the excellent spatstat package to fit an inhomogeneous Matern
> cluster point process model, but unfortunately I'm unable to simulate new
> data points from the fitted object.
>
> Specifically, I get the following error message:
>
>
> Error in rthin(result, P) :
>    some points of X lie outside the domain of image P
>
> I've toyed around a bit, and apparently the error only occurs if the window
> enclosing the analyzed point pattern is derived from a polygon, and the
> fitted model is inhomogeneous (includes covariates). Moreover, whether the
> error occurs appears to be dependent on some idiosyncrasies in the analyzed
> point patterns, i.e., in the example provided below changing the random
> seed will sometimes make the simulation work.
>
> I'm using spatstat 1.37-0 with R 3.1.0 on a x86_64-w64-mingw32/x64 (64-bit)
> machine.
>
> Here's some reproducible code:
>
>> require(spatstat)> set.seed(0)> > # Create an irregular window> poly.mat <- matrix(c(1,0,0.5,1,0,0), 3, 2, byrow=TRUE)> poly.owin <- owin(poly=poly.mat)> > # Generate Matern points> matern.ppp <- rMatClust(50, 0.05, 5, win=poly.owin)> > # Some distance function as a covariate> distorigin <- function(x, y) {+   sqrt(x^2 + y^2)+ }> > # No covariates: works fine> homogeneous.fit <- kppm(matern.ppp, ~ 1, clusters="MatClust") > matern.sim <- simulate(homogeneous.fit, retry=0)> > # Covariates: Simulation fails> inhomogeneous.fit <- kppm(matern.ppp, ~ distorigin, clusters="MatClust") > matern.sim <- simulate(inhomogeneous.fit, retry=0)Error in rthin(result, P) :
>    some points of X lie outside the domain of image PWarning message:In
> simulate.kppm(inhomogeneous.fit, retry = 0) :
>    1 simulation was unsuccessful: returned as NULL
>
>
> I'm fairly new to working with spatstat, so I might be missing something
> very basic. Any ideas on what I'm doing wrong? Many thanks for your help.



More information about the R-help mailing list