# [R] spatstat rmh problem

Sebastian Schutte schuttesebastian at gmail.com
Tue Sep 16 06:30:21 CEST 2014

```Thanks so much for your comments. Sorry for not having sent a running
example from the start. Here it is:

library (spatstat)

data(demopat)
#Generate a random point pattern within the polygon
set.seed(12345)
pdat <- rpoint(200,win=demopat\$window)
#Generate a distmap, which will serve as covariate information
im.cdat <- as.im(distmap(pdat))
#Now the random seed is fixed and a new set of random points is
generated for the example
set.seed(11111)
pdat <- rpoint(200,win=demopat\$window)
#Fitting a model to the data
mod <- ppm (pdat ~  im.cdat)
#Now a point pattern is simulated via rmh from the fitted model an
visualized as a density surface
set.seed(22222)
plot(density(rmh(mod)))
#And here is the problem: When I repeat the exercise with different
coefs, the very same patter come out. "new.coef" has no effect.
set.seed(22222)
plot(density(rmh(mod),new.coef=c(1,200)))

What am I missing?

Thanks again,
Sebastian

On 16.09.2014 00:18, Rolf Turner wrote:
>
> Your example is not reproducible.  We don't have "cshape" or "im.pop"
> (and are possibly lacking other bits and pieces; I didn't check the
> details since the example fails to run from the get-go).  Please
> provide a *reproducible* example.
>
> Also I am puzzled by the line
>
>> mod <- ppm (ppp, ~  pop ,  covariates = list (pop = im.pop))
>
> Did you mean
>
>> mod <- ppm (dat, ~  pop ,  covariates = list (pop = im.pop))
>
> ???
>
> Also please note that with versions of spatstat later than or equal to
> 1.37-0 you can write
>
>     ppm(dat ~ im.pop)
>
> when the object "im.pop" is present in the global environment.
>
> cheers,
>
> Rolf Turner
>
> On 16/09/14 02:30, Sebastian Schutte wrote:
>> Dear R and spatstat developers,
>>
>> Thanks so much for the time and effort that you invest into this awesome
>> software. I have a problem simulating from a Point Process Model in
>> spatstat. In summary, the option "new.coef" should allow me to use a
>> fitted model and change its beta coefficients before simulating a point
>> pattern from the model via Monte Carlo simulation. Intuitively, one
>> would assume that the predicted point pattern changes as one fiddles
>> with the beta coefficients. However, this does not seem to work.
>>
>> Please let me know what I am missing here and which screw to drive to
>> actually change the simulation output.
>>
>> #owin is a polygon of country boundaries, "im.pop" is a raster with
>> georeferenced population counts.
>> #I am using a random point pattern for demonstration purposes
>>
>> #Fix random seed
>> set.seed(12345)
>> #Generate artificial points
>> dat <- rpoint(500,win=cshape)
>> #Fit a (inhomogenous spatial poisson) model to the data
>> mod <- ppm (ppp, ~  pop ,  covariates = list (pop = im.pop))
>> #Simulate some points:
>> plot(density(rmh(mod)))
>> #plot(density(simulate(mod)))
>> #Show that this is reproducible
>> set.seed(12345)
>> #Generate artificial points
>> dat <- rpoint(500,win=cshape)
>> #Fit a (inhomogenous spatial poisson) model to the data
>> mod <- ppm (ppp, ~  pop ,  covariates = list (pop = im.pop))
>> #Simulate some points:
>> plot(density(rmh(mod)))
>> #As expected, the density is the same
>>
>> #Now change the coefs and do it again:
>> set.seed(12345)
>> #Generate artificial points
>> dat <- rpoint(500,win=cshape)
>> #Fit a (inhomogenous spatial poisson) model to the data
>> mod <- ppm (ppp, ~  pop ,  covariates = list (pop = im.pop))
>> #Simulate some points:
>> plot(density(rmh(mod),new.coef=c(1,200)))
>> #Looks the same, so what am I missing?
>

```