library(spatstat)
data(longleaf)
X <- unmark(longleaf)
# inhomogeneous point pattern
# fit Poisson point process with log-cubic intensity
fit.3 <- mpl(X, ~ polynom(x,y,3), Poisson())
# fit Poisson process with log-cubic-harmonic intensity
fit.h <- mpl(X, ~ harmonic(x,y,3), Poisson())
# Likelihood ratio test
lrts <- 2 * (fit.3$maxlogpl - fit.h$maxlogpl)
x <- X$x
y <- X$y
df <- ncol(polynom(x,y,3)) - ncol(harmonic(x,y,3))
pval <- 1 - pchisq(lrts, df=df)
Run the code above in your browser using DataCamp Workspace