简体   繁体   English

是否可以在 R 中给定另一个潜在的空间点模式来分析空间点模式

[英]Is it possible to analyse a spatial point pattern given another, underlying, spatial point pattern in R

I want to analyse the type of spatial pattern shown by an animal (ie random, clustered, uniform) taking into consideration the underlying spatial pattern of it's available habitat.我想分析动物所显示的空间模式类型(即随机、集群、统一),同时考虑到其可用栖息地的潜在空间模式。 The animals in question roost in trees, so a standard analysis of the animal spp will always show a clustered distribution (ie clustering around trees), but I want to test whether there is clustering between trees vs whether they distribute randomly throughout trees.有问题的动物栖息在树上,因此对动物 spp 的标准分析将始终显示聚类分布(即围绕树木聚类),但我想测试树木之间是否存在聚类,以及它们是否在整个树木中随机分布。 To provide a visual, I want to be able to differentiate between the following scenarios in the image:为了提供视觉效果,我希望能够区分图像中的以下场景:

https://imgur.com/a/iE3nAoh (image not allowed because I'm new to stack overflow, but it's available through the link) https://imgur.com/a/iE3nAoh (图片不允许,因为我是堆栈溢出的新手,但可以通过链接获得)

Here is a reproducible data frame.这是一个可重现的数据框。 The scenario here is of uniform habitat (25 areas of habitat) and uniform animals (16 animals per habitat):这里的场景是统一的栖息地(25 个栖息地)和统一的动物(每个栖息地 16 只动物):

library(spatstat)
data <- data.frame(matrix(ncol = 4, nrow = 25))
x <- c("habitat", "x", "y", "animalcount")
colnames(data) <- x
data$habitat <- 1:25
data$x <- seq(from=2, to=20, by=4)
data$y[1:5] <- 2
data$y[6:10] <- 6
data$y[11:15] <- 10
data$y[16:20] <- 14
data$y[21:25] <- 18
data$animalcount <- 16

Set up conditions for the spatial analysis:为空间分析设置条件:

plot.win <- owin(c(0,20), c(0,20)) # set the plot window as 20x20m
nS <- 499 # number of simulations
cd <- 5 # cluster distance
ed <- 50 # envelope distance
incr.dist <- 0.5 # increment distance for envelopes

Create the point pattern for the habitat:为栖息地创建点模式:

habitat <- ppp(x = data$x, y = data$y, window = plot.win)

Create the point pattern for the animals.为动物创建点图案。 To do this, first make a new dataframe with repeated rows for the number in animal count, so that points are individual animals.为此,首先制作一个新的 dataframe,在动物计数中重复行,以便点是个体动物。 Jitter x/y so that x/y coordinates are not exactly the same:抖动 x/y 以使 x/y 坐标不完全相同:

data <-data[which(data$animalcount>0),]
duplicate_rows <- function(habitat, x, y, animalcount) {
  expanded <- paste0("animal-", 1:animalcount)
  repeated_rows <- data.frame("habitat" = habitat, "x" = x, "y" = y, "animalcount" = expanded)
  repeated_rows
}
expanded_rows <- Map(f = duplicate_rows, data$habitat, data$x, data$y, data$animalcount)
animal_data <- do.call(rbind, expanded_rows)
animal_data$xan <- jitter(animal_data$x)
animal_data$yan <- jitter(animal_data$y)

animal <- ppp(x = animal_data$xan, y = animal_data$yan, window = plot.win)

Now test Complete Spatial Randomness of animals regardless of habitat.现在测试动物的完全空间随机性,而不考虑栖息地。 This should come out as clustered:这应该是集群的:

an.csr <- envelope(animal, Kest, nsims = nS, savepatterns = TRUE, r = seq(0, ed, incr.dist), correction=c("Ripley"), verbose = FALSE) #CSR fit and determine the number of simulations
an.dclf <- dclf.test(an.csr, rinterval = c(0,cd), verbose = FALSE) #calculate the summary statistics of the CSR null model fit (dclf.test)
plot(an.csr, sqrt(./pi)-r~r, ylab="L(r)-r", xlab="r (meters)", xlim=c(0,ed), legend="NULL", main=paste("Animal - CSR", sep = "")) #plot 0-centered fit with the confidence bounds 
clarkevans(animal)[2] #R > 1 suggests ordering, < 1 suggests clustering
clarkevans.test(animal, "Donnelly")$p

Now test Complete Spatial Randomness of animals, given the available habitat.现在测试动物的完全空间随机性,给定可用的栖息地。 This should come out not clustered.这应该不是聚集的。 But simply adding habitat as a covariate clearly isn't the appropriate way to do it:但简单地将栖息地添加为协变量显然不是合适的方法:

an.csr <- envelope(animal, covariates = animal_data[,2:3], Kest, nsims = nS, savepatterns = TRUE, r = seq(0, ed, incr.dist), correction=c("Ripley"), verbose = FALSE)
an.dclf <- dclf.test(an.csr, rinterval = c(0,cd), verbose = FALSE) 
plot(an.csr, sqrt(./pi)-r~r, ylab="L(r)-r", xlab="r (meters)", xlim=c(0,ed), legend="NULL", main=paste("Animal - CSR", sep = "")) 
clarkevans(animal)[2] 
clarkevans.test(animal, "Donnelly")$p

I also tried running the test of Complete Spatial Randomness on a fitted Point Process Model, where the animal point pattern could be predicted by x&y, but this also did not change outcomes:我还尝试在拟合点过程 Model 上运行完全空间随机性测试,其中可以通过 x&y 预测动物点模式,但这也没有改变结果:

animalppm<-ppm(animal~x+y)
an.csr <- envelope(animalppm, Kest, nsims = nS, savepatterns = TRUE, r = seq(0, ed, incr.dist), correction=c("Ripley"), verbose = FALSE) 
an.dclf <- dclf.test(an.csr, rinterval = c(0,cd), verbose = FALSE) 
plot(an.csr, sqrt(./pi)-r~r, ylab="L(r)-r", xlab="r (meters)", xlim=c(0,ed), legend="NULL", main=paste("Animal - CSR", sep = "")) 
clarkevans(animalppm)[2] #R > 1 suggests ordering, < 1 suggests clustering
clarkevans.test(animalppm, "Donnelly")$p

From there I would run tests of aggregation models, but the logic of adding the second point pattern should be similar.从那里我会运行聚合模型的测试,但添加第二个点模式的逻辑应该是相似的。

I would appreciate any suggestions on ways to deal with this.我将不胜感激有关处理此问题的方法的任何建议。 I cannot think of an effective way to google this, and am coming up short on clever coding solutions in R.我想不出一种有效的方法来搜索这个,并且在 R 中缺少聪明的编码解决方案。 Thanks in advance!提前致谢!

You can model the intensity as depending on the distance to the habitat pattern.您可以 model 强度取决于到栖息地模式的距离。 Here is a simple example where the animals follow a Poisson point process with intensity function which decays log-linearly with distance to the habitat:这是一个简单的例子,其中动物遵循强度为 function 的泊松点过程,该过程随到栖息地的距离呈对数线性衰减:

library(spatstat)

data <- expand.grid(x = seq(2, 18, by=4), y = seq(2, 18, by=4))
data$animalcount <- 16

plot.win <- owin(c(0,20), c(0,20)) # set the plot window as 20x20m

habitat <- ppp(x = data$x, y = data$y, window = plot.win)

d <- distmap(habitat)
plot(d)

lam <- exp(3-2*d)
plot(lam)

animal <- rpoispp(lam)
plot(animal)

fit <- ppm(animal ~ d)
fit
#> Nonstationary Poisson process
#> 
#> Log intensity:  ~d
#> 
#> Fitted trend coefficients:
#> (Intercept)           d 
#>    2.952048   -1.974381 
#> 
#>              Estimate       S.E.   CI95.lo   CI95.hi Ztest      Zval
#> (Intercept)  2.952048 0.07265533  2.809646  3.094450   ***  40.63085
#> d           -1.974381 0.07055831 -2.112673 -1.836089   *** -27.98226

Taking the underlying non-homogeneous intensity into account there is no sign of departure from the Poisson model in the (inhomogeneous) K-function:考虑到潜在的非均匀强度,在(非均匀)K 函数中没有偏离泊松 model 的迹象:

plot(Kinhom(animal, lambda = fit))
#> Warning: The behaviour of Kinhom when lambda is a ppm object has changed
#> (in spatstat 1.37-0 and later). See help(Kinhom)

You don't have to have simple log-linear dependence on distance.您不必对距离有简单的对数线性依赖性。 You could also make a threshold model where you have one intensity with eg distance 1 of the habitat and another intensity outside this distance.您还可以设置一个阈值 model ,其中您有一个强度,例如距离栖息地 1 和该距离之外的另一个强度。 You can make all kinds of derived covariates from eg the distance for use in your model.您可以根据距离制作各种派生协变量,例如在 model 中使用。

If animals is the point pattern of animals, and trees is the point pattern of trees (both objects of class "ppp" in spatstat) then you could do如果animals是动物的点模式,而trees是树的点模式(spatstat 中 class "ppp" 的两个对象),那么你可以这样做

d <- distfun(trees)
f <- rhohat(animals, d)
plot(f)

to get an idea of how the concentration of animals depends on distance to nearest tree.了解动物的集中度如何取决于到最近的树的距离。 You can use您可以使用

berman.test(animals, d)

to perform a hypothesis test of dependence on the trees.对树的依赖性进行假设检验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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