这个问题对于你们中的一些人来说可能是微不足道的,但事实就是如此。我实际上试图用截距和单个变量来模拟一个简单的非齐次点过程。我的目标只是使用 spatstat 和 rstan 包恢复这 2 个系数。
这是模拟的代码:
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 …
Run Code Online (Sandbox Code Playgroud)