# \donttest{
# 2-scenario, 2-group simulation
scen8 <- make.scenarios (D = 8, g0 = 0.3, sigma = 30,
noccasions = c(4,8), groups = c('F','M'))
# replace density and sigma values of males to make it interesting
male <- scen8$group == 'M'
scen8$D[male] <- 4
scen8$sigma[male] <- 40
grid <- make.grid(8, 8, spacing = 30)
mask <- make.mask(grid, buffer = 160, type = 'trapbuffer')
old <- options(digits = 3)
setNumThreads(2)
#--------------------------------------------------------------------------
# run a few simulations
# model groups
sims <- run.scenarios(10, scen8, trapset = grid, fit = TRUE,
fit.args = list(model = list(D~g, g0~1, sigma~g), groups = 'group'),
extractfn = predict, maskset = mask)
# format as list, selecting statistics
# default summary uses true = c(8,4,8,4)
estimateSummary(sims, 'D', c("true", "nvalid", "EST", "RB", "seRB"))
# format as data.frame by scenario and group, all statistics
estimateSummary(sims, 'D', format = 'data.frame')
#--------------------------------------------------------------------------
# try with default extractfn (single table per replicate, despite groups)
sims2 <- run.scenarios(10, scen8, trapset = grid, fit = TRUE,
maskset = mask)
# Fails with "Error in estimateSummary(sims2, "D") : incongruent 'true'""
# estimateSummary(sims2, 'D')
# OK if manually provide scenario-specific true density
estimateSummary(sims2, 'D', true = c(12,12))
# reformat by scenario
estimateSummary(sims2, 'D', true = c(12,12), format = 'data.frame')
# compare standard summary
summary(sims2)$OUTPUT
#--------------------------------------------------------------------------
# multiple estimate tables also arise from multi-session simulations
# argument 'true' must be specified manually
# interpret with care: sessions are (probably) not independent
# this example uses the previous grid and mask
scen9 <- make.scenarios (D = 8, g0 = 0.3, sigma = 30, noccasions = 5)
poparg <- list(nsessions = 3, details = list(lambda = 1.2)) # for sim.popn
detarg <- list(renumber = FALSE) # for sim.capthist
fitarg <- list(model = D~Session) # for secr.fit
sims3 <- run.scenarios(5, scen9, trapset = grid, fit = TRUE,
maskset = mask, pop.args = poparg, det.args = detarg,
fit.args = fitarg, extractfn = predict)
estimateSummary(sims3, parameter = 'D', format = 'data.frame',
true = 8 * 1.2^(0:2))
#--------------------------------------------------------------------------
# extractfn = coef results in a single estimate table per replicate,
# so the usual summary method is sufficent. For completeness we show
# that estimateSummary can also be used. Coefficients are often negative,
# so relative values (e.g., RB, RSE) may be meaningless.
sims4 <- run.scenarios(5, scen9, trapset = grid, fit = TRUE,
maskset = mask, pop.args = poparg, det.args = detarg,
fit.args = fitarg, extractfn = coef)
estimateSummary(sims4, parameter = 'D', c("nvalid", "EST", "seEST", "RMSE", "COV"),
format = 'data.frame', true = log(8), checkfields = 'beta',
validrange = log(c(2,20)))
estimateSummary(sims4, parameter = 'D.Session', c("nvalid", "EST", "seEST",
"RMSE", "COV"), format = "data.frame", true = log(1.2), checkfields = "beta",
validrange = log(c(0.5,2)))
#--------------------------------------------------------------------------
options(old)
# }
Run the code above in your browser using DataLab