Fwd: read capthist error & mixture model error

280 views
Skip to first unread message

Shannon Braun

unread,
Dec 19, 2018, 2:48:17 AM12/19/18
to secr...@googlegroups.com
I intended to send the below error to the group instead of replying to Murray directly. Thanks for the help Murray, my mask looks great.

Hopefully somebody out there has some insights into my problem. To troubleshoot the mixture model fail error below I attempted to change the first detector to a 1 on the first day instead of a zero in the OUT session of my traps file. No matter how I save the file I get an error when I try to make my capthist object. All I want for Christmas is my secr results.

Error in read.table(file, row.names = 1, as.is = T, colClasses = colcl, : 
duplicate 'row.names' are not allowed

Thanks in advance and merry xmas.


---------- Forwarded message ---------
From: Shannon Braun <shannon...@gmail.com>
Date: Sat, 15 Dec. 2018, 13:53
Subject: Re:
To: Murray Efford <murray...@gmail.com>


Cheers Murray. That worked well and I'm stoked to have finally solved that issue. I am so close to having my final results now but I ran into another error which I cannot solve.

I have attempted to integrate this mask and your modified input of the data into my previous analysis that I successfully completed without a multi session mask. After your changes I am unable to run mixture models. I get the below error from line 158 of the attached code and wonder if this is an easy fix.

Error in FUN(X[[i]], ...) :

 
 mixture models fail when the first detector is not 

  
                      used on the first day




To help you understand my intentions as clearly as possible I have attached all of my code. I appreciate your insights into the approach I have taken. My workflow so far has been this. Identify h2 effect on g0 and sigma. Sigma was the best model. I then tested for bk and time trend, and previously neither were better than null. I then checked for how session effected parameters and because h2 effecting sigma was previously the best model, I included h2 with sigma for every model comparison. You can see what I've done in the attached code.

I'm pretty excited about what I'm learning in secr so if I have time before my deadlines my next step is to make use of a shape file I created with a habitat covariate for the entire mask. I was considering running density surface models so that I can see if density varies relative to habitat and potentially model some kind of East West trend to see if parameters are different relative to the fence (would this be non-Euclidian distances). Also parameters may vary differently for adults and juveniles.  

Thanks for your time Murray.

On Fri, Dec 14, 2018 at 8:02 PM Murray Efford <murray...@gmail.com> wrote:
I editted your captfile so all session = 1 (see attached), then implemented my earlier suggestion. It seems no cameras were working on last 2 days outside the fence, so I shortened that. Seems to work with secr.fit(bothCH, mask = masks,...)


###Input files and create capthist####
captfile
<- "captfile_both.xlsx"
trapfile
<- "trapfile_both.csv"

buffer
<- 800
bothCH
<- read.capthist(captfile = captfile, trapfile = trapfile,
                        skip
= 1, detector = "proximity",
                        covnames
= c("age"))            

bothCH
<- split(bothCH, grepl('IN',rownames(traps(bothCH))), bytrap = TRUE)

# drop last 2 occasions for OUT (no cameras working)
bothCH
[[1]] <- subset(bothCH[[1]], occasions=1:78)
usage
(traps(bothCH[[1]])) <- usage(traps(bothCH[[1]]))[,1:78]

#### Clear repeat observations
bothCH
<- reduce(bothCH, dropunused = FALSE)    
verify
(bothCH)

session
(bothCH) <- c('OUT',"IN")
par
(mfrow = c(1,2))
plot
(bothCH)

Insidepoly <- rgdal::readOGR("mask_in.shp", stringsAsFactors = FALSE)
maskoutside
<- make.mask(traps(bothCH[[1]]), buffer = buffer, type = 'trapbuffer',
                    poly
= Insidepoly, poly.habitat = FALSE)
maskinside
<- make.mask(traps(bothCH[[2]]), buffer = buffer, type = 'trapbuffer',
                    poly
= Insidepoly, poly.habitat = TRUE)
masks
<- list(maskoutside, maskinside)

par
(mfrow=c(1,2))
plot
(maskoutside)
plot
(traps(bothCH[[1]]), add = TRUE)
mtext
(side=3, 'OUT')
plot
(maskinside)
plot
(traps(bothCH[[2]]), add = TRUE)
mtext
(side=3, 'IN')


On Thursday, December 13, 2018 at 11:33:00 PM UTC+13, Shannon Braun wrote:

Hi Murray and group,

I have spent considerable time trying to troubleshoot some secr problems myself having read Murrays vignettes, the notes from his workshop I attended (great workshop Murray) and many forums. I really would appreciate some guidance please. 

I am comparing the density and ranging behaviour of goannas inside and outside of a predator excluded fence. Each side of the fence has 36 camera detectors that are approximately 180m apart and form a six by six detector grid. The detector grids are actually quite close to the fence, some detectors as close as 50 metres.

I have taken a multi session approach with the detector grids on each side of the fence being considered as two separate sessions. Because the detector array for both sessions are so close together the buffer zones overlap and this needs to be taken into consideration when building my habitat mask. I need a mask for inside the fence that excludes the polygon outside of the fence and a mask for the session outside the fence that excludes the polygon inside the fence.

My understanding is that I must create a list of traps objects that is then put into the traps argument for each of my two masks. Then I need to combine those two masks as a list that becomes the mask that is read into the secr.fit function. So far I am ok excluding the non-habitat area for creating a mask for both sessions and I can combine them into a list. I am not sure how to handle my traps files. I have tried to make separate trap files by deleting the non-required detectors rows from the csv file and when I try to use read.traps with the edited file I get this error message.

Error in read.table(file, row.names = 1, as.is = T, colClasses = colcl,  :

  duplicate 'row.names' are not allowed

 

 

 I don’t understand how to fix this. Read.traps works perfectly fine prior to editing out the non required rows of the file that are for the other sessions detectors. I am pretty sure I cannot use the file that includes traps from both sessions and that I need to create a list of traps (one traps object for each session).

 

The relevant code so far is below.

###Input files and create capthist####

captfile <- "captfile_both.csv"

trapfile <- "trapfile_both.csv"

trapfile_both<- read.csv("trapfile_both.csv")

 

buffer <- 800

 

bothCH <- read.capthist(captfile = captfile,

                        trapfile = trapfile,

                        sep = ",", skip = 1,

                        detector = "proximity",       

                        covnames = c("age")

)            

#### Clear repeat observations and subset sessions#####

bothCH <- reduce(bothCH, dropunused = FALSE)     # clear out repeat observations

verify(bothCH)

 

inside_CH <- subset(bothCH, session = c(1))

outside_CH <- subset(bothCH, session = c(2))

 

###Create traps object, read polygons using rgdal and create masks###

trapfile_both  <- read.traps(trapfile,

                             sep = ",",

                             skip = 1,               

                             detector = "proximity")

******read.traps works fine when using the original trap file with both sessions traps. When I delete one of the sessions I get the above mentioned error about row names. I am pretty sure I need two traps files read in as objects that I then use to create a list and that list is read into the traps argument of make.mask*********

 

Insidepoly<-rgdal::readOGR("mask_in.shp", stringsAsFactors = FALSE)

 

Outsidepoly<-rgdal::readOGR("mask_out.shp", stringsAsFactors = FALSE)

 

 

 

maskinside <- make.mask(trapfile_both,

                        spacing = 50,

                        buffer = buffer,

                        type = 'trapbuffer',

                        poly = Outsidepoly,

                        poly.habitat = FALSE,

                        keep.poly = TRUE,

                        check.poly = TRUE)

 

maskoutside <- make.mask(trapfile_both,

                         spacing = 50,

                         buffer = buffer,

                         type = 'trapbuffer',

                         poly = Insidepoly,

                         poly.habitat = FALSE,

                         keep.poly = TRUE,

                         check.poly = TRUE)

mask<-list(maskinside, maskoutside)

 

I’m also having trouble trying to plot this and I suspect it may in part be due to me trying to use a single traps object that is not listed by session with a list of masks. Otherwise something may be wrong with the below code which I attempted to adapt from your multi session vignette. I can only get one mask to plot and it does not include the trapfiles. When I adjust the order of the two masks in my list then it seems to effect which mask gets plotted so I suspect it is only plotting the first mask in the list. I also get an error message.

 

par(mfrow = c(1,2), mar = c(5,4,4,2))

for(sess in 1:length(trapfile_both)) {

  plot(mask[[sess]])

  plot(traps(trapfile_both)[[sess]], add = TRUE) }

 

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In plot.window(...) : "add" is not a graphical parameter

 

All of my models have run fine without the multi session mask but I suspect my estimates will change once I exclude non-habitat.

I have attached my traps and capthist files for reference. Any advice is greatly appreciated. I am flailing at the moment.

 

Cheers

 


--
Shannon Braun

PhD candidate
Department of Ecology, Environment and Evolution | La Trobe University | Bundoora, 3086 Australia

--
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.
For more options, visit https://groups.google.com/d/optout.


--
Shannon Braun

PhD candidate
Department of Ecology, Environment and Evolution | La Trobe University | Bundoora, 3086 Australia
Goanna secr post Murrays mask.R

Murray Efford

unread,
Dec 20, 2018, 3:34:15 PM12/20/18
to Shannon Braun, secr
Hi Shannon
Sending lots of code makes it less likely you will get help. I can't see where you are going wrong - probably something simple in the way you have edited your input (which we cannot see).  Please isolate the problem you are having and present it in the simplest way possible.
Murray

Shannon Braun

unread,
Jan 18, 2019, 6:18:03 PM1/18/19
to Murray Efford, secr
Hi Murray and group,

Apologies for being unclear. My main problem is that when I implement the changes you assisted me with I get an error.

Here is a re-cap on what you had sent me from the below string in December.
"On Fri, Dec 14, 2018 at 8:02 PM Murray Efford <murray.efford@gmail.com> wrote:
I editted your captfile so all session = 1 (see attached), then implemented my earlier suggestion. It seems no cameras were working on last 2 days outside the fence, so I shortened that. Seems to work with secr.fit(bothCH, mask = masks,...)"

The changes you made to my files with the code you gave me worked to create the multi-session mask I needed but now I can no longer perform mixture models that were previously working fine. Below is an example.

                   fit_age0 <- secr.fit(bothCH, mask = mask,  detectfn = 2, trace = F, hcov = 'age')

                   Error in FUN(X[[i]], ...) : 
                   mixture models fail when the first detector is not 
                                                       used on the first day

 I'm sure this is a simple fix but I have not been able to find a solution. A steer in the right direction would be great.

Cheers

Murray Efford

unread,
Jan 18, 2019, 8:23:00 PM1/18/19
to Shannon Braun, secr
The present code requires a '1' in the first position of the usage matrix for a fairly arcane reason (and laziness on my part). The next version of secr is more robust, but won't be out for a week or so. Meantime I suggest you fake it by putting a '1' in that position - I promise it will make almost no difference to the estimates.
Murray

Shannon Braun

unread,
Jan 18, 2019, 9:27:54 PM1/18/19
to Murray Efford, secr
Thanks Murray. I did try that I believe by changing the first detector to a 1 on the first day (instead of a zero), in the OUT session of the traps file. No matter how I save the exel file I get an error when I try to make my capthist object with the modified traps file. I've tried saving as .csv and saving it as a .txt.

I figured this was a trivial issue but some accomplished r users are unsure of why this is happening. 

Error in read.table(file, row.names = 1, as.is = T, colClasses = colcl, : 
duplicate 'row.names' are not allowed

But if you think the new version of secr will solve my mixture model issue I can wait until that is released.

Thanks for your help.

Murray Efford

unread,
Jan 18, 2019, 9:43:47 PM1/18/19
to Shannon Braun, secr
I'm not really following. If you're keen you could get a provisional copy of secr 3.2.0 from https://www.otago.ac.nz/density/zip/secr_3.2.0.zip (Windows binary) or https://www.otago.ac.nz/density/zip/secr_3.2.0.tar.gz (source). On Windows you just use Packages | Install package(s) from local files.
Murray
Reply all
Reply to author
Forward
0 new messages