Error messgae specific to R & secr version

118 views
Skip to first unread message

Ayan Sadhu

unread,
Jun 22, 2024, 2:52:24 AM6/22/24
to secr
While running secr models on R version - 4.4.1 (secr version - 4.6.7), I am getting an error reading the capture history file - 
" Error in read.traps(data = tmp, detector = "count") : 'usage' fields suggest varying number of occasions"

However, no such error existed in the trap file, and when I tried running the same model in an old version of R (3.6.1, secr version—3.2.1), it worked. For now, I have prepared the workspace in the older version and am running it on my workstation (as it's much faster than my laptop), but I want to resolve this issue. Apart from this, this particular R & secr version on my workstation acted weirdly sometime ago when the likelihood was not converging (showing NA for all the iterations), while the same dataset worked perfectly for the older version of R & secr. Now, I am wondering whether there are some issues in my workstation, as I have not encountered similar issues in this group for the 4.6x version.

Your help/thoughts on this are greatly appreciated.
Warm regards

Code: (highlighted the line where I am getting the error mentioned above)
library(secr)
cameratrap <- read.csv("trap_4367.csv", head = T)
tmp <- cameratrap
cameratrap <- read.traps(data = tmp, detector = "count")
row.names(cameratrap) <- tmp$trap_ID
cameratrap <- split(cameratrap, tmp$Site)
##<truncated>##

Murray Efford

unread,
Jun 23, 2024, 6:01:17 PM6/23/24
to secr
Hello
This is likely to be a data or secr issue rather than an R issue per se. All sorts of things changed between secr 3.x and secr 4.x (mostly for the better!), and you definitely want to be using the newer version.
Getting all-NA likelihood evaluations usually indicates difficulty with starting values, and sometimes if you are close to the edge it takes very little to tip over.
I can't be specific without seeing the data -I'm happy to have a look if you send me an example (data and code) that misbehaves.
Murray

Murray Efford

unread,
Jun 27, 2024, 7:08:41 PM6/27/24
to secr
Thanks for sending the data and code. I see several problems.

1. The help for read.traps specifies "If file is missing then x-y coordinates will be taken instead from data, which should include columns ‘x’ and ‘y’. Row names of data are read as detector identifiers unless trapID is specified. This option does not allow for covariates or usage, but they maybe added later."
So your code should read something like

tmp <- read.csv("trap.csv")
cameratrap <- read.traps(data = tmp[,2:4], trapID = 'trapid', detector = "count")
usage(cameratrap) <- tmp[,5:124]

2. In the call to make.capthist you need quotes in noncapt = "NONE"
3. Package rgdal is no longer available so use package sf, e.g. sf::st_read("Shiv_Mask.shp")
4. I don't know what species you have, but a starting density of 4/hectare seems implausible
5. You have many sites ('sessions') and many of them have no or few detections. I'm not surprised that fitting a uniform model hits problems.
6. The sample sizes do not justify fitting elaborate density models. I was able to fit reasonable null models separately to each site with recaptures, and prehaps you can build from there.

Murray
Reply all
Reply to author
Forward
0 new messages