Trap covariates in simulations

20 views
Skip to first unread message

stefano palmero

unread,
Apr 17, 2025, 5:31:40 AMApr 17
to secr
Hi all,
I would like to include trap types (on/off road) in my SECRDESIGN scenarios but I am not sure how to do it.
First of all, trap types should be specified in the trap file.
When I know type-specific g0s, should I create two groups? Something like this:

## Scenarios
densities <- c(5e-05,1e-04,1.5e-04,2e-04)
g0 <- 0.01
sigmas <- c(3000,4000,5000)

scen <- make.scenarios(noccasions = c(60,80,100,120), nrepeats = 1,
                       D = densities * 0.75,
                       sigma = sigmas,
                       g0 = g0,
                       groups = c('on','off'))
off <- scen$group == 'off'
scen$g0[off] <- 0.02

and then of course g0~traptype etc...

But I am not sure about communication between trap file, scenarios and the model in this case

Thank you very much
Stefano

Murray Efford

unread,
Apr 17, 2025, 6:31:22 PMApr 17
to stefano palmero, secr
Hi Stefano
Groups could work (examples at https://github.com/MurrayEfford/secr-simulations under STR). But there is a more direct way using explicit input of detector-specific detection parameters in sim.capthist. For a different reason (aiming to reduce number of occasions)  I started out with HHN instead of HN (hence lambda0 instead of g0), but this should also work with HN/g0. It's not pretty, but it seems to get there.
Murray

library(secrdesign)

# some detectors with a binary covariate 1,2
grid<- make.grid(8,8, spacing = 5000, detector = 'proximity')
onoff <- sample.int(2, nrow(grid), replace = TRUE)
covariates(grid) <- data.frame(onoff = onoff)
plot(secr::as.mask(grid), cov='onoff', dots = FALSE)

lambdas <- c(0.01,0.02)  # for covariate levels 1,2
sigmas  <- c(3000,4000,5000)

# manually construct some occasion x detector matrix inputs for sim.capthist
# (ultimately replaces lambda0, sigma from scen)
onedetpar <- function (noccasions, sigma) {
# filling by row re-uses detector-specific covariates on each occasion
mat <- matrix(lambdas[onoff], byrow = TRUE, nrow = noccasions, ncol = nrow(grid))
    list(detectpar = list(lambda0 = mat, sigma = sigma))
}
# all combinations of duration and sigma
dets <- expand.grid(noccasions = c(60,80,100,120), sigma = sigmas)
detarglist <- mapply(onedetpar, dets$noccasions, dets$sigma, SIMPLIFY = FALSE)


## Scenarios
densities <- c(5e-05,1e-04,1.5e-04,2e-04)
scen <- make.scenarios(
noccasions = 60,       # placeholder - replaced later

D          = densities * 0.75,
detectfn   = 'HHN',
lambda0    = 0.01,     # placeholder - replaced later
sigma      = 3000,     # placeholder - replaced later
detindex   = 1:12)

# force noccasions to follow matrices in detarg
scen$noccasions <- dets$noccasions[scen$detindex]

sims <- run.scenarios(
nrepl     = 20,
scenarios = scen,
trapset   = grid,
det.args  = detarglist,
fit       = TRUE,
fit.args  = list(detectfn = 'HHN', model = lambda0~onoff))

estimateSummary(sims)


--
You received this message because you are subscribed to the Google Groups "secr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to secrgroup+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/secrgroup/8310ff0e-f1c7-42a6-ad83-d649e57f4a48n%40googlegroups.com.

stefano palmero

unread,
Apr 30, 2025, 8:40:14 AMApr 30
to Murray Efford, secr
Dear Murray,
Thank you very much for the help, as always.
I'll try this code out

Best

Stefano Palmero


Faculty of Environment and Natural Resources

University of Freiburg

Tennenbacher Straße 4

79106 Freiburg

Germany


Reply all
Reply to author
Forward
0 new messages