Trap Covariates in openCR

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Trap Covariates in openCR

Postby ctlamb » Tue Jul 31, 2018 3:05 pm

I am running into an issue with trap covariates in openCR which I have attempted to replicate here:

Code: Select all
  ##Replicate trapcov error

##setup data and masks
ovenCHr <- rotate(ovenCHp, 90) # rotate for horizontal plot
nets <- traps(ovenCHr)[[1]]
msk <- make.mask(nets, buffer = 300, nx = 50, type = "trapbuffer")


##add in random trapcov. Couldn't find example data with trapcovs
  for(i in 1:length(session(ovenCHp))){
    covariates(traps(ovenCHp)[[i]])$binom <- rbinom(n=nrow(traps(ovenCHp)[[i]]), prob=0.7, size=1)
   
  }
##re-assign class
class(ovenCHp) <- class(ovenCHr)

##check to make sure covariates are present
head(covariates(traps(ovenCHp[[1]])))
# binom
# 1     0
# 2     1
# 3     1
# 4     1
# 5     0
# 6     1
#

##fit model
fit <- openCR.fit(ovenCHp, type = 'JSSAsecrlCL', model = lambda0~binom, mask = msk)

##Error in openCR.design(capthist, model, type, timecov = timecov, sessioncov = sessioncov,  :
##covariate(s) binom not found
ctlamb
 
Posts: 51
Joined: Mon Nov 04, 2013 9:44 pm

Re: Trap Covariates in openCR

Postby murray.efford » Wed Aug 01, 2018 10:31 am

It looks like in-situ changes to an attribute (covariates) of an attribute (traps) of a component (session CH) of a capthist list (ovenCHr/p) are not working, and ad-hoc re-assignment of class does not solve the problem. Probably need to work on getting the right data structure, perhaps by re-building the ms capthist with trap covariates added before building capthist.
Murray
murray.efford
 
Posts: 531
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Trap Covariates in openCR

Postby ctlamb » Wed Aug 01, 2018 10:37 am

Perhaps my attempt to replicate this error is confusing things. Sorry about that.

I have a caphist that I have loaded in with trapcov's:

Code: Select all
 read.capthist(here::here( "Data","CapData", paste0(projects[[i]])),
                         here::here("Data","TrapData", paste0(projects[[i]])),
                        detector ="proximity",
                        trapcovnames="Trap_Type",
                        sep = ",")


This capthist successfully runs with Trap_Type using secr.fit:
Code: Select all
dsecr.b.trap <- secr.fit(capthist = grizzCH.d, model = list(D~1, g0~bk+Trap_Type, sigma~1), mask = GBmask.d)


But not openCR.fit:
Code: Select all
osecr.b.trap <- openCR.fit(capthist = grizzCH, mask= GBmask.o, type = 'JSSAsecrlCL', list(lambda0~b+Trap_Type, sigma~1))

##covariate(s) Trap_Type not found
ctlamb
 
Posts: 51
Joined: Mon Nov 04, 2013 9:44 pm

Re: Trap Covariates in openCR

Postby murray.efford » Wed Aug 01, 2018 10:41 am

OK It's time I checked an example myself and confronted the real issue with trap covariates in openCR.fit. Will get back on this.
Murray
murray.efford
 
Posts: 531
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Trap Covariates in openCR

Postby murray.efford » Wed Aug 01, 2018 11:55 am

It turns out that I did not code detector covariates in openCR.design, used by openCR.fit (it needs just one extra line). This is inconsistent with the vignette (which says detector covariates are OK) but may have been a semi-conscious design decision: these models are going to fit very slowly. Another example where openCR does not reproduce the full range of options in secr.

I have added the missing line, but unfortunately I cannot immediately rebuild openCR for distribution as I'm traveling for the next 6 weeks and Windows 10 on my laptop obstructs R package builds (cygwin1.dll problem due to a 2017 security update that cannot be rolled back?). I'll look for a workaround (learning to use GitHub?), but can't promise one.

Murray
murray.efford
 
Posts: 531
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Trap Covariates in openCR

Postby murray.efford » Wed Aug 01, 2018 11:59 am

By the way, I was able to insert detector covariates like this

Code: Select all
##Replicate trapcov error
library(openCR)

##setup data and masks
ovenCHr <- rotate(ovenCHp, 90) # rotate for horizontal plot
nets <- traps(ovenCHr)[[1]]

##add in random trapcov. Couldn't find example data with trapcovs
for(i in 1:length(session(ovenCHr))){
    ch <- ovenCHr[[i]]
    covariates(traps(ch)) <- data.frame(binom = rbinom(n = nrow(traps(ch)), prob = 0.7, size = 1))
    ovenCHr[[i]] <- ch
}

##check to make sure covariates are present
head(covariates(traps(ovenCHr[[1]])))
# binom
# 1     0
# 2     1
# 3     1
# 4     1
# 5     0
# 6     1

##fit model
ch <- join(ovenCHr) ## warning
fit <- openCR.fit(ch, type = 'JSSAsecrlCL', model = lambda0~binom, mask = msk, trace = TRUE)

##Error in openCR.design(capthist, model, type, timecov = timecov, sessioncov = sessioncov,  :
##covariate(s) binom not found

murray.efford
 
Posts: 531
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Trap Covariates in openCR

Postby ctlamb » Wed Aug 01, 2018 2:00 pm

Thanks, Murray. Great that you were able to isolate and that this seems to be a "simple" fix. Bummer about the version issues for updating package. Please let me know if/when you are able to update the package or find a work around. Keen to run these models on our bear data! Thanks again
ctlamb
 
Posts: 51
Joined: Mon Nov 04, 2013 9:44 pm


Return to analysis help

Who is online

Users browsing this forum: No registered users and 1 guest