I am currently writing my thesis on camera trap designs for a region in the Western Cape, South Africa. I have hit a brick wall with regards to simulating a capture histories where sigma is dependent on sex. For context, the population is first simulated (with estimated parameters and a known pmix) before simulating the capture history and fitting the model with secr.fit and model args of D~elev and sigma~h2. I could not find any direct method of separating the sigma values by sex and so I tried ideas found on this message board which resulted in the following:
Simulating Population
- Code: Select all
my_pop <- sim.popn(D = D, core = masks, buffer = 0, Ndist = sim.popn.Ndist,poly =mask.poly$geometry,covariates = list(sex = c(M = 0.4375,F = 0.5625)))
Simulating Capture History
- Code: Select all
ch.M <- try(sim.capthist(traps = grids, pop = my_pop[covariates(my_pop)$sex=="M",],
noccasions = 1,
detectpar = list(lambda0 = 1, sigma =5100),
detectfn = "HHN"))
ch.F <- try(sim.capthist(traps = grids, pop = my_pop[covariates(my_pop)$sex=="F",],
noccasions = 1,
detectpar = list(lambda0 = 1, sigma = 2360),
detectfn = "HHN"))
covariates(ch.M)$sex <- try(factor(rep("M",dim(ch.M)[1])))
covariates(ch.F)$sex <- try(factor(rep("F",dim(ch.F)[1])))
ch.total<-try(MS.capthist(Females=ch.F,Males=ch.M,renumber=T))
ch.total<-try(shareFactorLevels(ch.total))
ch.total<-try(rbind(ch.total$Females,ch.total$Males))
levels(covariates(ch.total)$sex)<-c("M","F")
Fitting Model
- Code: Select all
startvals <- list(D = mean(D), lambda0 = 1, sigma = sigma_pooled)
if (sum(covariates(ch.total)$sex=="F")==0){ #to avoid issues when no females caught
model.args = list(D ~ elev, sigma~1)
}else{
model.args = list(D ~ elev, sigma~g)
}
mod <- try(secr.fit(capthist = ch.total,ncores=9,mask = masks_red, model = model.args, groups = "sex", binomN = secr.binomN, detectfn = "HHN", start = startvals, trace = FALSE, details = list(distribution = secr.dbn),method = "Nelder-Mead"))
This method resulted in decent estimations of the true simulated values of sigma but also resulted in systematically bad estimates of lambda0 as well as hilariously inconsistent results which make me inclined to believe that there is a huge issue with the way I've coded this (maybe theoretical, maybe code-based).
I would just like to ask if there's an easier or more straightforward method to do this. In the case that this method should be working, I'll then know to look for bugs in my code.
A sample of the results are shown below with estimates varying by the number of cameras used in the trap array where "B" is "Bias".

These may not seem abhorent but in we were getting some lambda0 estimates (using designs which are known to be good) with 200% bias or more. This, along with the fact that more cameras should mean better estimates which is not the case in my results, indicates to me that there is a structural issue at play. Any help will be appreciated beyond words.
edit: I should specify that the results shown are the aggregate of 50 iterations of the process described above.