Page 1 of 1

region.N for non-euclidean models

PostPosted: Fri Apr 27, 2018 2:47 pm
by samanthamcfar
Hello Murray,

I'm having trouble running region.N for my models that include non-euclidean distances. I'm using the "habitat model for connectivity" method from the noneuclidean vignette. My top two models both include non-euclidean distances:

wsar.fit.noneuc.g0.10km <- secr.fit(WSARCH,mask=wsar_10km_mask, model = list(noneuc~bio, g0~t), trace=FALSE, details = list(userdist = fn2), fixed = list(sigma=1), method = "Nelder-Mead")

wsar.fit.NULL.noneuc.10km <- secr.fit(WSARCH,mask=wsar_10km_mask, model = list(D~bio, noneuc~bio), trace=FALSE, details = list(userdist = fn2), fixed = list(sigma=1), method = "Nelder-Mead")

fn2 is the function provided from the vignette.

However, when I attempt to run region.N to estimate N within my population range, I keep getting the following error:
region.N(Top_Model, popmask, spacing = 2000, se.N = TRUE)
Error in euc/sig : non-conformable arrays

Any suggestions?

Thanks
Sam

Re: region.N for non-euclidean models

PostPosted: Sat Apr 28, 2018 7:11 am
by murray.efford
region.N fails also with the possum model in the vignette. It seems this can be fixed by a small change in fn2 (coercing sig1 and sig2 to vectors before 'outer'):

Code: Select all
fn2 <- function (xy1, xy2, mask) {
  if (missing(xy1)) return("noneuc")
  xy1 <- addCovariates(xy1, mask)
  xy2 <- addCovariates(xy2, mask)
  sig1 <- as.numeric(covariates(xy1)$noneuc)   # sigma(x,y) at detectors
  sig2 <- as.numeric(covariates(xy2)$noneuc)   # sigma(x,y) at mask points
  euc <- edist(xy1, xy2)
  sig <- outer (sig1, sig2, FUN = function(s1, s2) (s1 + s2)/2)
  euc / sig
}


I hope this works for you.
Murray

Re: region.N for non-euclidean models

PostPosted: Sat Apr 28, 2018 7:49 pm
by murray.efford
I tracked this down to an internal function (predictD) that returned a 1-column matrix instead of a vector. It should be fixed in the next release, but that is not imminent. In the meantime use the modified fn2 in my last post.
Murray

Re: region.N for non-euclidean models

PostPosted: Mon Apr 30, 2018 10:36 am
by samanthamcfar
Thank you so much Murray. I changed the fn2 code and am re-running my non-euc models now, I will let you know if this fixes the issue!

Thanks,
Sam