I'm trying to simulate a log gaussian cox process based on an image array for the covariate field, and a matern covariance function for the GMRF field, based pretty much exactly on the example given in "Advanced Spatial Modeling with Stochastic Partial Differential Equations Using R and INLA" (https://becarioprecario.bitbucket.io/spde-gitbook/ch-lcox.html). However the code as its written in the online textbook is throwing a warning when it generates the LGCP.
The code used is here:
library(spatstat)
win <- owin(c(0, 3), c(0, 3))
npix <- 300
spatstat.options(npixel = npix)
beta0 <- 3
sigma2x <- 0.2
range <- 1.2
nu <- 1
set.seed(7)
x0 <- seq(0, 3, length=npix)
y0 <- seq(0, 3, length=npix)
gridcov <- outer(x0, y0, function(x,y) cos(x) - sin(y - 2))
beta1 <- 0
sum(exp(beta0 + beta1 * gridcov) * diff(x0[1:2]) * diff(y0[1:2]))
lg.s.c <- rLGCP('matern', im(beta0 + beta1 * gridcov, xcol = x0,
yrow = y0), var = sigma2x, scale = range / sqrt(8),
nu = 1, win = win)
xy.c <- cbind(lg.s.c$x, lg.s.c$y)[, 2:1]
n.c <- nrow(xy.c)
Lam <- attr(lg.s.c, 'Lambda')
rf.s.c <- log(Lam$v)
The returned warning is the images ‘e1’ and ‘e2’ were not compatible and the resulting intensity field rf.s.c has dimensions 562 x 562 whereas the the input x and y arrays are 1x100 (the intensity field should be 100 x 100), and is entirely NA values.
Could someone help me understand this warning and why the example is failing?
This may very well be a bug in
spatstat. Recently, new code was added for simulation of LGCPs due to the package RandomFields no longer being on CRAN. We will investigate further and you can track the status of the issue on GitHub: https://github.com/spatstat/spatstat.random/issues/2