data(lansing)
# inhomogeneous pattern of maples
X <- unmark(split(lansing)$maple)
<testonly>sub <- sample(c(TRUE,FALSE), X$n, replace=TRUE, prob=c(0.1,0.9))
X <- X[sub , ]</testonly>
# (1) intensity function estimated by model-fitting
# Fit spatial trend: polynomial in x and y coordinates
fit <- ppm(X, ~ polynom(x,y,2), Poisson())
# predict intensity values at points themselves
lambda <- predict(fit, locations=X, type="trend")
# inhomogeneous K function
Ki <- Kinhom(X, lambda)
plot(Ki)
# (2) intensity function estimated by heavy smoothing
smo <- density.ppp(X, sigma=0.1)
# evaluate smoothed intensity at data points
lambda <- smo[X]
# inhomogeneous K function
Ki <- Kinhom(X, lambda)
plot(Ki)
# (3) simulated data: known intensity function
lamfun <- function(x,y) { 100 * x }
# inhomogeneous Poisson process
Y <- rpoispp(lamfun, 100, owin())
# evaluate intensity at points of pattern
lambda <- lamfun(Y$x, Y$y)
# inhomogeneous K function
Ki <- Kinhom(Y, lambda)
plot(Ki)
# How to make simulation envelopes:
# Example shows method (2)
smo <- density.ppp(X, sigma=0.1)
myKfun <- function(X, ..., lam) { Kinhom(X, lambda=lam[X], ...) }
Ken <- envelope(X, myKfun, nsim=99,
simulate=expression(rpoispp(smo)),
lam=smo, correction="trans")
plot(Ken)
Run the code above in your browser using DataCamp Workspace