## The `ovensong' data are pooled from 75 replicate positions of a
## 4-microphone array. The array positions are coded as the first 4
## digits of each sound identifier. The sound data are initially in the
## object `signalCH'. We first impose a 52.5 dB signal threshold as in
## Dawson & Efford (2009, J. Appl. Ecol. 46:1201--1209). The vector nj
## includes 33 positions at which no ovenbird was heard. The first and
## second columns of `temp' hold the estimated effective sampling area
## and its standard error.
signalCH.525 <- subset(signalCH, cutval = 52.5)
nonzero.counts <- table(substring(rownames(signalCH.525),1,4))
nj <- c(nonzero.counts, rep(0, 75 - length(nonzero.counts)))
temp <- derived(ovensong.model.1, se.esa = TRUE)
derived.nj(nj, temp["esa",1:2])
## The result is very close to that reported by Dawson & Efford
## from a 2-D Poisson model fitted by maximizing the full likelihood.
## If nj vector has length 1, a theoretical variance is used...
msk <- ovensong.model.1$mask
A <- nrow(msk) * attr(msk, "area")
derived.nj (sum(nj), temp["esa",1:2], method = "poisson")
derived.nj (sum(nj), temp["esa",1:2], method = "binomial", area = A)
## Not run: ------------------------------------
#
# ## Set up an array of small (4 x 4) grids,
# ## simulate a Poisson-distributed population,
# ## sample from it, plot, and fit a model.
# ## mash() condenses clusters to a single cluster
#
# testregion <- data.frame(x = c(0,2000,2000,0),
# y = c(0,0,2000,2000))
# t4 <- make.grid(nx = 4, ny = 4, spacing = 40)
# t4.16 <- make.systematic (n = 16, cluster = t4,
# region = testregion)
# popn1 <- sim.popn (D = 5, core = testregion,
# buffer = 0)
# capt1 <- sim.capthist(t4.16, popn = popn1)
# fit1 <- secr.fit(mash(capt1), CL = TRUE, trace = FALSE)
#
# ## Visualize sampling
# tempmask <- make.mask(t4.16, spacing = 10, type =
# "clusterbuffer")
# plot(tempmask)
# plot(t4.16, add = TRUE)
# plot(capt1, add = TRUE)
#
# ## Compare model-based and empirical variances.
# ## Here the answers are similar because the data
# ## were simulated from a Poisson distribution,
# ## as assumed by \code{derived}
#
# derived(fit1)
# derived.mash(fit1)
#
# ## Now simulate a patchy distribution; note the
# ## larger (and more credible) SE from derived.mash().
#
# popn2 <- sim.popn (D = 5, core = testregion, buffer = 0,
# model2D = "hills", details = list(hills = c(-2,3)))
# capt2 <- sim.capthist(t4.16, popn = popn2)
# fit2 <- secr.fit(mash(capt2), CL = TRUE, trace = FALSE)
# derived(fit2)
# derived.mash(fit2)
#
# ## The detection model we have fitted may be extrapolated to
# ## a more fine-grained systematic sample of points, with
# ## detectors operated on a single occasion at each...
# ## Total effort 400 x 1 = 400 detector-occasions, compared
# ## to 256 x 5 = 1280 detector-occasions for initial survey.
#
# t1 <- make.grid(nx = 1, ny = 1)
# t1.100 <- make.systematic (cluster = t1, spacing = 100,
# region = testregion)
# capt2a <- sim.capthist(t1.100, popn = popn2, noccasions = 1)
# ## one way to get number of animals per point
# nj <- attr(mash(capt2a), "n.mash")
# derived.external (fit2, nj = nj, cluster = t1, buffer = 100,
# noccasions = 1)
#
# ## Review plots
# library(MASS)
# base.plot <- function() {
# eqscplot( testregion, axes = FALSE, xlab = "",
# ylab = "", type = "n")
# polygon(testregion)
# }
# par(mfrow = c(1,3), xpd = TRUE, xaxs = "i", yaxs = "i")
# base.plot()
# plot(popn2, add = TRUE, col = "blue")
# mtext(side=3, line=0.5, "Population", cex=0.8, col="black")
# base.plot()
# plot (capt2a, add = TRUE,title = "Extensive survey")
# base.plot()
# plot(capt2, add = TRUE, title = "Intensive survey")
# par(mfrow = c(1,1), xpd = FALSE, xaxs = "r", yaxs = "r") ## defaults
## ---------------------------------------------
Run the code above in your browser using DataLab