Building a loop to calculate cumulative estimates from camtrapR detection histories

43 views
Skip to first unread message

Jarrad Barnes

unread,
Feb 23, 2020, 8:47:01 AM2/23/20
to unmarked
Hi all, I have a number of detection histories produced in camtrapR from camera trapping data and am interested in calculating cumulative detection probability from occasion 1 to occasion n. I know I can do this in a long-winded way by truncating each detection history to 1 occasion, then 2 occasions, 3 occasions, etc., but this will take a considerable amount of time with 9 detection histories and 50-60 occasions in most of those, and increases the risk of simply misplacing information with all the data frames that will be produced

I'm hoping that there might be a way to set up a loop so that I can automate this process to fill in a blank matrix, preferably with p and upper and lower 95% confidence intervals (i.e. a 3-row matrix, with varying columns depending on the detection history used). I have no real experience working with loops, but perhaps somebody here has experience doing just that and might be able to help out. I think a for loop is the way I need to go about doing this, but I don't know how I would set up the loop to iterate cumulative occasions from 1 to n. Any ideas?

Thanks,
Jarrad
Message has been deleted

Jarrad Barnes

unread,
Feb 23, 2020, 11:20:46 PM2/23/20
to unmarked
For those interested, I think this is the way to do it, at least to get detection probabilities quickly calculated to show how it changes over time. I imagine it's reasonably straightforward to work out cumulative detection probability from the resulting matrix:

Dets <- dat[,-1] #produce detection history without "station" col



pmat
<- matrix(nrow = 1, ncol = 58) #produce empty matrix of 1 row and cols = ncol(Dets)


for(i in seq_along(pmat)) {
m1
<- occu(~1 ~1, data = unmarkedFrameOccu(y = Dets[1:i]))
m1
.psi <- backTransform(m1, type = "state")
m1
.p <- backTransform(m1, type = "det")
pmat
[i] = m1.p@estimate
}
Reply all
Reply to author
Forward
0 new messages