## Simple example: generate and summarise trapping data
## at two densities and for two levels of sampling frequency
scen1 <- make.scenarios(D = c(5,10), sigma = 25, g0 = 0.2, noccasions =
c(5,10))
traps1 <- make.grid() ## default 6 x 6 trap grid
tmp1 <- run.scenarios(nrepl = 20, trapset = traps1, scenarios = scen1,
fit = FALSE)
summary(tmp1)
if (FALSE) {
setNumThreads(7)
##########################################
# new summary method (secrdesign >= 2.8.1)
# assumes fit = TRUE, extractfn = predict
tmp2 <- run.scenarios(nrepl = 10, trapset = traps1, scenarios = scen1,
fit = TRUE, extractfn = predict)
estimateSummary(tmp2, format = "data.frame",
cols = c('scenario', 'noccasions'))
###########################
## 2-phase example
## first make and save rawdata
scen1 <- make.scenarios(D = c(5,10), sigma = 25, g0 = 0.2)
traps1 <- make.grid() ## default 6 x 6 trap grid
tmp1 <- run.scenarios(nrepl = 20, trapset = traps1, scenarios = scen1,
fit = FALSE, extractfn = identity)
## review rawdata
summary(tmp1)
## then fit and summarise models
tmp2 <- fit.models(tmp1, fit.args = list(list(model = g0~1),
list(model = g0~T)), fit = TRUE)
summary(tmp2)
###########################
## Construct a list of detector arrays
## Each is a set of 5 parallel lines with variable between-line spacing;
## the argument that we want to vary (spacey) follows nx, ny and spacex
## in the argument list of make.grid().
spacey <- seq(2000,5000,500)
names(spacey) <- paste('line', spacey, sep = '.')
trapset <- lapply(spacey, make.grid, nx = 101, ny = 5, spacex = 1000,
detector = 'proximity')
## Make corresponding set of masks with constant spacing (1 km)
maskset <- lapply(trapset, make.mask, buffer = 8000, spacing = 1000,
type = 'trapbuffer')
## Generate scenarios
scen <- make.scenarios (trapsindex = 1:length(spacey), nrepeats = 8,
noccasions = 2, D = 0.0002, g0 = c(0.05, 0.1), sigma = 1600, cross = TRUE)
## RSE without fitting model
sim <- run.scenarios (50, scenarios = scen, trapset = trapset, maskset = maskset,
fit = TRUE, fit.args = list(method = 'none'), seed = 123)
## Extract statistics for predicted density
sim <- select.stats(sim, parameter = 'D')
## Plot to compare line spacing
summ <- summary (sim, type='array', fields = c('mean','lcl','ucl'))$OUTPUT
plot(0,0,type='n', xlim=c(1.500,5.500), ylim = c(0,0.36), yaxs = 'i',
xaxs = 'i', xlab = 'Line spacing km', ylab = 'RSE (D)')
xv <- seq(2,5,0.5)
points(xv, summ$mean[,1,'RSE'], type='b', pch=1)
points(xv, summ$mean[,2,'RSE'], type='b', pch=16)
segments(xv, summ$lcl[,1,'RSE'], xv, summ$ucl[,1,'RSE'])
segments(xv, summ$lcl[,2,'RSE'], xv, summ$ucl[,2,'RSE'])
legend(4,0.345, pch=c(1,16), title = 'Baseline detection',
legend = c('g0 = 0.05', 'g0 = 0.1'))
}
Run the code above in your browser using DataLab