data(lansing)
# inhomogeneous pattern of maples
X <- unmark(lansing[lansing$marks == "maple",])
<testonly>sub <- sample(c(TRUE,FALSE), X$n, replace=TRUE, prob=c(0.1,0.9))
X <- X[sub , ]</testonly>
# fit spatial trend
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)
# 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)
Run the code above in your browser using DataCamp Workspace