空間分析  加分題

Bivariant K Function

助教 杜承軒 2020.05.17

Bivariate K function 與二元點隨機的方法介紹可以參考以下影片說明:
📢 108-2 空間分析 Bivariate K function (K-cross)

\(H_0:\) 兩者隨機
\(H_a:\) 兩者群聚,KFC在MIC附近
\(\alpha=0.05\)

library(rgdal);library(GISTools);library(spatstat);library(splancs)
setwd('D:/1082SA/Data')
FF=readOGR('Tpe_Fastfood.shp')

spatstat

default: random CRS + relabel

FF.ppp=ppp(FF@coords[,1],FF@coords[,2],FF@bbox[1,],FF@bbox[2,])
FF.ppp=FF.ppp %mark% FF$STORE
K=Kcross(FF.ppp,"KFC","MIC",correction = "none")
K.env=envelope(FF.ppp,Kcross,verbose=F,nsim=99,nrank=5,alternative = "greater")
plot(K.env,main="Kcross + envelope(default)")

random relabelling

K.rlabel=envelope(FF.ppp,Kcross,verbose=F,nsim=99,nrank=5,alternative = "greater",simulate=rlabel)
plot(K.rlabel,main="Kcross + envelope(rlabel)")

random toroidal shifts

K.rshift=envelope(FF.ppp,Kcross,verbose=F,nsim=99,nrank=5,alternative = "greater",simulate=expression(rshift(FF.ppp)))
plot(K.rshift,main="Kcross + envelope(rshift)")

splancs

default: random toroidal shifts

s=seq(0,3000,100)
FF.pts=as.points(FF@coords[,1],FF@coords[,2])
KFC=FF.pts[FF$STORE=="KFC",];MIC=FF.pts[FF$STORE=="MIC",]
x1=FF@bbox[1,1];x2=FF@bbox[1,2];y1=FF@bbox[2,1];y2=FF@bbox[2,2]
BND=as.points(c(x1,x2,x2,x1,x1),c(y1,y1,y2,y2,y1))
tpe.k12=k12hat(KFC,MIC,BND,s)
env12=Kenv.tor(KFC,MIC,BND,19,s,quiet=T)
plot(s, tpe.k12, type="l",xlab="dist", ylab="K(d)",main="k12hat + Kenv.tor")
polygon(c(s,rev(s)),c(env12$upper,rep(0,length(s))),col='grey',border = NA)