online <- interactive()
if(!online) {
# reduce grid sizes for efficiency in tests
spatstat.options(npixel=32, ndummy.min=16)
}
# fit the stationary Poisson process
# to point pattern 'nztrees'
ppm(nztrees ~ 1)
if(online) {
Q <- quadscheme(nztrees)
ppm(Q ~ 1)
# equivalent.
}
fit1 <- ppm(nztrees ~ x)
# fit the nonstationary Poisson process
# with intensity function lambda(x,y) = exp(a + bx)
# where x,y are the Cartesian coordinates
# and a,b are parameters to be estimated
fit1
coef(fit1)
coef(summary(fit1))
ppm(nztrees ~ polynom(x,2))
# fit the nonstationary Poisson process
# with intensity function lambda(x,y) = exp(a + bx + cx^2)
if(online) {
library(splines)
ppm(nztrees ~ bs(x,df=3))
}
# Fits the nonstationary Poisson process
# with intensity function lambda(x,y) = exp(B(x))
# where B is a B-spline with df = 3
ppm(nztrees ~ 1, Strauss(r=10), rbord=10)
# Fit the stationary Strauss process with interaction range r=10
# using the border method with margin rbord=10
ppm(nztrees ~ x, Strauss(13), correction="periodic")
# Fit the nonstationary Strauss process with interaction range r=13
# and exp(first order potential) = activity = beta(x,y) = exp(a+bx)
# using the periodic correction.
# Compare Maximum Pseudolikelihood, Huang-Ogata and Variational Bayes fits:
if(online) ppm(swedishpines ~ 1, Strauss(9))
ppm(swedishpines ~ 1, Strauss(9), method="VBlogi")
ppm(swedishpines ~ 1, Strauss(9), improve.type="ho",
nsim=if(!online) 8 else 99)
# Elastic net fit:
if(require(glmnet)) {
ppm(swedishpines ~ x+y, Strauss(9), improve.type="enet")
}
# COVARIATES
#
X <- rpoispp(20)
weirdfunction <- function(x,y){ 10 * x^2 + 5 * sin(10 * y) }
#
# (a) covariate values as function
ppm(X ~ y + weirdfunction)
#
# (b) covariate values in pixel image
Zimage <- as.im(weirdfunction, unit.square())
ppm(X ~ y + Z, covariates=list(Z=Zimage))
#
# (c) covariate values in data frame
Q <- quadscheme(X)
xQ <- x.quad(Q)
yQ <- y.quad(Q)
Zvalues <- weirdfunction(xQ,yQ)
ppm(Q ~ y + Z, data=data.frame(Z=Zvalues))
# Note Q not X
# COVARIATE FUNCTION WITH EXTRA ARGUMENTS
#
f <- function(x,y,a){ y - a }
ppm(X ~ x + f, covfunargs=list(a=1/2))
# COVARIATE: logical value TRUE inside window, FALSE outside
b <- owin(c(0.1, 0.6), c(0.1, 0.9))
ppm(X ~ b)
## MULTITYPE POINT PROCESSES ###
# fit stationary marked Poisson process
# with different intensity for each species
if(online) {
ppm(lansing ~ marks, Poisson())
} else {
ama <- amacrine[square(0.7)]
a <- ppm(ama ~ marks, Poisson(), nd=16)
}
# fit nonstationary marked Poisson process
# with different log-cubic trend for each species
if(online) {
ppm(lansing ~ marks * polynom(x,y,3), Poisson())
} else {
b <- ppm(ama ~ marks * polynom(x,y,2), Poisson(), nd=16)
}
Run the code above in your browser using DataLab