随机点数据

rm(list=ls())
Ntotal = 50 *50
xi.1 <- runif(n=Ntotal, min = 0,max = 500)
yi.1 <- runif(n=Ntotal, min = 0,max = 300)
plot(xi.1, yi.1)

随机栅格数据

x1.f <- factor(ceiling(xi.1/10), levels=1:50)
y1.f <- factor(ceiling(yi.1/10), levels=1:30)
xyTab.1 <- table(y1.f, x1.f) 
image(t(xyTab.1))
points(xi.1/500, yi.1/300, pch='*')

K函数: 随机点数据

require(spatstat)
## Loading required package: spatstat
## 
## spatstat 1.38-1       (nickname: 'Le Hardi') 
## For an introduction to spatstat, type 'beginner'
X <- ppp(xi.1, yi.1, window=owin(c(0,500),c(0,300)),check=T)
KK <- Kest(X,correction = 'border')
plot(KK)

##        lty col    key           label                           meaning
## border   1   1 border hat(K)[bord](r) border-corrected estimate of K(r)
## theo     2   2   theo      K[pois](r)          theoretical Poisson K(r)

聚集点数据

Nparents= 50 ; Nkids=50; SD=3
x0 <- runif(n=Nparents, min = 10, max = 490)
y0 <- runif(n=Nparents, min = 10, max = 290)
xi.c <- rep(x0, each=Nkids) + rnorm(n=Nparents * Nkids, mean=0, sd=SD)
yi.c <- rep(y0, each=Nkids) + rnorm(n=Nparents * Nkids, mean=0, sd=SD)
plot(xi.c, yi.c)

聚集栅格数据

xf <- factor(ceiling(xi.c/10), levels=1:50)
yf <- factor(ceiling(yi.c/10), levels=1:30)
xyTab.c <- table(yf, xf) 
image(t(xyTab.c))
points(xi.c/500, yi.c/300, pch='*')

K函数: 聚集点数据

Xc <- ppp(xi.c, yi.c, window=owin(c(0,500),c(0,300)),check=T)
KKc <- Kest(Xc,correction = 'border')
plot(KKc)

##        lty col    key           label                           meaning
## border   1   1 border hat(K)[bord](r) border-corrected estimate of K(r)
## theo     2   2   theo      K[pois](r)          theoretical Poisson K(r)

随机+聚集 点格局

xi <- c(xi.1, xi.c); yi <- c(yi.1, yi.c)
plot(xi, yi)

K函数: 随机+聚集 点格局

加入随机作用后,KKi比KKc的聚集强度降低。

Xi <- ppp(xi, yi, window=owin(c(0,500),c(0,300)),check=T)
KKi <- Kest(Xi,correction = 'border')
plot(KKi)
##        lty col    key           label                           meaning
## border   1   1 border hat(K)[bord](r) border-corrected estimate of K(r)
## theo     2   2   theo      K[pois](r)          theoretical Poisson K(r)
points(KKc$r, KKc$border, type='l', col=3)

异质K函数: 随机(+聚集) 点格局

剔除聚集效应后,异质inKi函数比KKi降低,接近随机作用。 inKi的随机理论标准增高。

env.im <- im(xyTab.c, xrange=c(0,500), yrange=c(0,300))
fit <- ppm(Xi, ~ env.im, Poisson())
lambda <- predict(fit, locations=Xi, type="trend")
inKi <- Kinhom(Xi, lambda, correction = 'border')
plot(KKi)
##        lty col    key           label                           meaning
## border   1   1 border hat(K)[bord](r) border-corrected estimate of K(r)
## theo     2   2   theo      K[pois](r)          theoretical Poisson K(r)
points(inKi$r, inKi$border, type='l', col=3)
points(inKi$r, inKi$theo, type='l', col=2)

异质K函数: (随机+)聚集 点格局

剔除随机效应后,异质inKi1函数比KKi升高。inKi1的理论标准回到pi*r^2。

env1.im <- im(xyTab.1, xrange=c(0,500), yrange=c(0,300))
fit1 <- ppm(Xi, ~ env1.im, Poisson())
lambda1 <- predict(fit1, locations=Xi, type="trend")
inKi1 <- Kinhom(Xi, lambda1, correction = 'border')
plot(KKi)
##        lty col    key           label                           meaning
## border   1   1 border hat(K)[bord](r) border-corrected estimate of K(r)
## theo     2   2   theo      K[pois](r)          theoretical Poisson K(r)
points(inKi1$r, inKi1$border, type='l', col=3)
points(inKi1$r, inKi1$theo, type='l', col=2)

(完)