简体   繁体   中英

Simulate inhomogenous poisson point process and retrieve the covariate coefficients

This question may be trivial for some of you but here it is. I am actually trying to simulate a simple inhomogenous point process with an intercept and a single variable. My goal is only to recover these 2 coefficients using the package spatstat and rstan.

Here is the code for the simulation:

library(spatstat)
library(sf)
library(sp)
library(maptools)
library(raster)
library(fields)
library(rstan)
library(tidyverse)

# Generate species distribution
genDat_pp <- function(b1, b2, dim, plotdat = TRUE){

# Define the window of interest
win <- owin(c(0,dim[1]), c(0,dim[2]))

# set number of pixels to simulate an environmental covariate
spatstat.options(npixel=c(dim[1],dim[2]))

y0 <- seq(win$yrange[1], win$yrange[2],
        length=spatstat.options()$npixel[2])
x0 <- seq(win$xrange[1], win$xrange[2],
        length=spatstat.options()$npixel[1])
multiplier <- 1/dim[2]

# Make the environmental covariate
gridcov <- outer(x0,y0, function (x,y) multiplier*y + 0*x)

# Set the coefficients
beta0 <- b1
beta1 <- b2

# Simulate the point pattern
pp <- rpoispp(im(beta0 + beta1*gridcov, xcol=x0, yrow=y0))
qcounts <- quadratcount(pp, ny=dim[1], nx=dim[2])
dens <- density(pp)
Lambda <- as.vector(t(qcounts))

if(plotdat == TRUE){
  par(mfrow=c(1,2), mar=c(2,2,1,1), mgp=c(1,0.5,0))
  plot(im(gridcov), main = 'Covariate')
  plot(dens, main = 'Intensity')
}
# Return a list with which I can play with
return(list(Lambda = Lambda, pp = pp, gridcov = gridcov))
}

Now, the simulation seems to work and return coherent plots. However when I try to "analyse" the data using spatstat I cannot recover the intercept or the beta coefficient:

b1 <- 2
b2 <- 5
dim <- c(20,20)

# Generate data
pp <- genDat_pp(b1, b2, dim)

# Fit a poisson point process model in spatstat
cov <- im(pp$gridcov)
fit <- ppm(pp$pp ~ 1 + cov)
summary(fit)

In this example the object "fit" tell me that the intercept is 2.65 (which is relatively okay) and the beta coefficient 2.68 which is totally wrong.

Is there any mistakes or am I just interpreting the result with a wrong perspective?

I would really appreciate anyone has an answer!

Ben

This question relates to the spatstat package.

In your example, the intensity function has the form a + b*Z where Z is a covariate function and a and b are numbers.

In the model-fitting function ppm , the model formula describes the logarithm of the intensity function. The model formula X ~ 1 + Z or equivalently X ~ Z (the 1 is redundant in this context) means that the log of the intensity of the point pattern X is assumed to be a linear function of the covariate Z . So the intensity function would be of the form exp(a + b * Z) where a and b are parameters that will be estimated when ppm is called.

The model that you're fitting, lambda = exp(a+bZ) , does not agree with the model that you simulated, lambda = a+bZ , hence the discrepancy in results.

This is explained further in the help file for ppm , and in chapter 9 of the spatstat book .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM