Problems with run.scenarios on a linear mask

45 views
Skip to first unread message

stefano palmero

unread,
Oct 18, 2024, 5:46:39 AM10/18/24
to secr
Hi all,
I am trying to use run.scenarios using a linear mask (attachment) and a non-Euclidean function.
I tried not to specify this in the code as the vignette says it (userdist = networkdistance) is default with a linear mask.

However, I get such a warning message for some scenarios (I am using 1 rep per scenario and only 12 rows to speed it up):

sims <- run.scenarios (1, scenarios = scens[1:12,],
                       trapset = simtraps, maskset = riversmask,
                       pop.args = list(model2D = 'linear'),
                       fit = TRUE, extractfn = predict, fit.function = 'secr.fit',
                       ncores = 12, byscenario = FALSE, seed = 345)

...
24: In (function (capthist, model = list(D ~ 1, g0 ~ 1, sigma ~ ... : using Euclidean distances with linear mask

Hence, I tried putting it in the det.args:

arg <- list(userdist = networkdistance)

sims <- run.scenarios (1, scenarios = scens[1:12,],
                       trapset = simtraps, maskset = riversmask,
                       det.args = list(arg),
                       pop.args = list(model2D = 'linear'),
                       fit = TRUE, extractfn = predict, fit.function = 'secr.fit',
                       ncores = 12, byscenario = FALSE, seed = 345)


However, I still get the same warning for some scenarios.

Finally, I tried using the fit.args and I get an error

arg <- list(userdist = networkdistance)

sims <- run.scenarios (1, scenarios = scens[1:12,],
                       trapset = simtraps, maskset = riversmask,
                       fit.args = list(arg),
                       pop.args = list(model2D = 'linear'),
                       fit = TRUE, extractfn = predict, fit.function = 'secr.fit',
                       ncores = 12, byscenario = FALSE, seed = 345)


Error in f(x, ...) : unused argument (userdist = function (xy1, xy2, geometry) { if (missing(xy1)) return(character(0)) rn <- list(rownames(xy1), rownames(xy2)) if (is.null(dim(xy1))) xy1 <- matrix(xy1, ncol = 2) if (is.null(dim(xy2))) xy2 <- matrix(xy2, ncol = 2) if (missing(geometry)) geometry <- xy2 gr <- attr(geometry, "graph") if (is.null(gr)) gr <- asgraph(geometry) geometryxy <- cbind(V(gr)$x, V(gr)$y) matchedxy1 <- nearesttrap(xy1, geometryxy) matchedxy2 <- nearesttrap(xy2, geometryxy) uniquematchedxy1 <- unique(matchedxy1) tmp <- t(igraph::shortest.paths(gr, weights = NULL, v = matchedxy2, to = uniquematchedxy1)) rematch <- match(matchedxy1, uniquematchedxy1) tmp <- tmp[rematch, , drop = FALSE] if (!("weight" %in% igraph::list.edge.attributes(gr))) tmp <- tmp * spacing(geometry) dimnames(tmp) <- rn tmp }) In addition: There were 13 warnings (use warnings() to see them) Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "try-error"

Mymask has an issue, it consists of 4 separate systems. Considering real data, individuals do not move across systems and thus "networkdistance" can be used. Perhaps in simulated scenarios, individuals are fabricated with detections across systems causing an issue in the model?

Thank you very much

Stefano









27ce2fa0-1dd0-40f0-a267-af5bdbcb5e6e.png

Murray Efford

unread,
Oct 21, 2024, 4:23:25 PM10/21/24
to secr
Hi Stefano

It always helps to provide a simple example. This works for me ('tho maybe not an ideal example):

library(secrlinear)
library(secrdesign)
scen <- make.scenarios(D = 30, g0 = 0.07, sigma = 50)
sims <- run.scenarios (5, scenarios = scen,
                       trapset = traps(arvicola), maskset = glymemask,

                       pop.args = list(model2D = 'linear'),
                       fit.args = list(details = list(userdist = networkdistance)),
                       fit = TRUE, seed = 123)

Network distance is not the default, as should have been clear from the vignette. I see -

"We can fit a spatially explicit model to the water vole data in
three ways: (i) ignoring the linearity of the habitat (fit2DEuc), (ii)
with a linear habitat map and the default Euclidean distance model
(fit1DEuc), or (iii) with both linear habitat and an appropriate
non-Euclidean distance function (fit1DNet):"

Is the default stated differently somewhere else?

A spurious warning 
mean.default(full.pop.args[[pi]]$D) : argument is not numeric or logical: returning NA
can be ignored, or avoided by setting D in pop.args. I have fixed it for the next version of secrdesign.

Murray

Murray Efford

unread,
Oct 23, 2024, 3:55:16 PM10/23/24
to secr
Prompted by Stefano off-list...

You are quite right about the default distance function in run.scenarios for linear masks: there is a major error in the documentation (section 'Linear habitat' of secrdesign-vignette.pdf). I can see nothing in the code that implements networkdistance as the default. 

I'm wondering how best to resolve this. It's easy to fix the vignette, and maybe provide a correct example. The trouble with making networkdistance the default in the package is that there are two places it might apply (data simulation, model fitting) and it's nice to allow these to be different, under user control as at present. Also, that vignette is not distributed with the package, so I wouldn't have to submit a new version of secrdesign. So I guess I'll just correct the vignette.

I put a new version of secrlinear on CRAN this week in response to your earlier point, but the Windows binary won't appear there for another day.

Murray
Reply all
Reply to author
Forward
0 new messages