temppop <- sim.popn (D = 10, expand.grid(x = c(0,100), y =
c(0,100)), buffer = 50)
## plot, distinguishing "M" and "F"
plot(temppop, pch = 1, cex= 1.5,
col = c("green","red")[covariates(temppop)$sex])
## add a continuous covariate
## assumes covariates(temppop) is non-null
covariates(temppop)$size <- rnorm (nrow(temppop), mean = 15, sd = 3)
summary(covariates(temppop))
## Neyman-Scott cluster distribution (see also rThomas)
par(xpd = TRUE, mfrow=c(2,3))
for (h in c(5,15))
for (m in c(1,4,16)) {
temppop <- sim.popn (D = 10, expand.grid(x = c(0,100),
y = c(0,100)), model2D = "cluster", buffer = 100,
details = list(mu = m, hsigma = h))
plot(temppop)
text (50,230,paste(" mu =",m, "hsigma =",h))
}
par(xpd = FALSE, mfrow=c(1,1)) ## defaults
## Inhomogeneous Poisson distribution
xy <- secrdemo.0$mask$x + secrdemo.0$mask$y - 900
tempD <- xy^2 / 1000
plot(sim.popn(tempD, secrdemo.0$mask, model2D = "IHP"))
## Coastal distribution in 1000-m square, homogeneous in
## x-direction
arena <- data.frame(x = c(0, 1000, 1000, 0),
y = c(0, 0, 1000, 1000))
plot(sim.popn(D = 5, core = arena, buffer = 0, model2D =
"coastal", details = list(Beta = c(1, 1, 5, 1))))
## Hills
plot(sim.popn(D = 100, core = arena, model2D = "hills",
buffer = 0, details = list(hills = c(-2,3,0,0))),
cex = 0.4)
## tile demonstration
pop <- sim.popn(D = 100, core = make.grid(), model2D = "coastal")
par(mfrow = c(1,2), mar = c(2,2,2,2))
plot(tile(pop, "copy"))
polygon(cbind(-100,200,200,-100), c(-100,-100,200,200),
col = "red", density = 0)
title("copy")
plot(tile(pop, "reflect"))
polygon(cbind(-100,200,200,-100), c(-100,-100,200,200),
col = "red", density = 0)
title("reflect")
if (FALSE) {
## simulate from inhomogeneous fitted density model
regionmask <- make.mask(traps(possumCH), type = "polygon",
spacing = 20, poly = possumremovalarea)
dts <- distancetotrap(regionmask, possumarea)
covariates(regionmask) <- data.frame(d.to.shore = dts)
dsurf <- predictDsurface(possum.model.Ds, regionmask)
possD <- covariates(dsurf)$D.0
posspop <- sim.popn(D = possD, core = dsurf, model = "IHP")
plot(regionmask, dots = FALSE, ppoly = FALSE)
plot(posspop, add = TRUE, frame = FALSE)
plot(traps(possumCH), add = TRUE)
## randomHabitat demonstration
## - assumes igraph has been installed
# The wrapper function randomDensity may be passed to generate
# a new habitat map each time sim.popn is called. The `details' argument
# of sim.popn is passed to randomDensity as the `parm' argument.
tempmask <- make.mask(nx = 100, ny = 100, spacing = 20)
pop <- sim.popn(D = randomDensity, core = tempmask, model2D = "IHP",
details = list(D = 10, p = 0.4, A = 0.5))
plot(attr(pop, 'mask'), cov = 'D', dots = FALSE)
plot(pop, add = TRUE)
## rLGCP demonstration
## - assumes spatstat and RandomFields have been installed
if (requireNamespace("spatstat") && requireNamespace("RandomFields")) {
msk <- make.mask(traps(captdata))
# details argument 'spacing' ensures core matches Lambda below
pop <- sim.popn(D = 20, core = msk, buffer = 0,
model2D = "rLGCP", details = list(var=1, scale = 30, saveLambda = TRUE),
seed = 1234)
plot(pop)
plot(traps(captdata), add = TRUE)
# another IHP realisation from same LGCP intensity surface
lgcp <- attr(pop, 'Lambda')
pop2 <- sim.popn(D = 'Lambda', core = lgcp, model2D = "IHP")
plot (lgcp, covariate = "Lambda", dots = FALSE)
plot (pop2, add = TRUE, frame = FALSE)
# check input and output masks match
summary(lgcp)
summary(msk)
}
}
Run the code above in your browser using DataLab