problem when using hcov

I am having some issue with models not working in secr version 4.3.1 (and also 4.2.x) when using hcov="sex" (where sex is a factor with F, M and NA). This is a large multi-survey dataset that was working fine in secr 3.1.5.
If I remove hcov everything works fine:
Digging a bit deeper I found that the issue only occurs if at least one of the surveys in capthist only has individuals of one sex. Any suggestions on how to fix this? The sex covariate is already coded as a factor with two levels (F and M).
Here code to reproduce the issue:
Thanks,
Mathias
- Code: Select all
> secr.0<- secr.fit (capthist ,model = list(g0~1,sigma~1,D~1), hcov='sex', buffer=buffer)
Checking data
Preparing detection design matrices
Preparing density design matrix
Finding initial parameter values...
Initial values D = 2e-05, g0 = 0.00527, sigma = 6574.44594
Maximizing likelihood...
Eval Loglik D g0 sigma pmix.h2M
1 NA -10.6871 -5.2411 8.7909 1.5000
2 NA -10.6871 -5.2411 8.7909 1.5000
3 NA -10.6871 -5.2411 8.7909 1.5000
.....
19 NA -10.6871 -5.2411 8.7918 1.5002
20 NA -10.6871 -5.2411 8.7909 1.5003
Completed in 69.84 seconds at 22:36:17 01 Sep 2020
If I remove hcov everything works fine:
- Code: Select all
> secr.0<- secr.fit (capthist ,model = list(g0~1,sigma~1,D~1), buffer=buffer)
Checking data
Preparing detection design matrices
Preparing density design matrix
Finding initial parameter values...
Initial values D = 2e-05, g0 = 0.00503, sigma = 6574.44594
Maximizing likelihood...
Eval Loglik D g0 sigma
1 -2219.929 -10.7166 -5.2868 8.7909
2 -2219.929 -10.7166 -5.2868 8.7909
3 -2219.928 -10.7166 -5.2868 8.7909
.....
65 -2086.951 -9.7860 -4.4418 8.4692
66 -2086.953 -9.7860 -4.4419 8.4700
Completed in 99.19 seconds at 22:39:02 01 Sep 2020
Digging a bit deeper I found that the issue only occurs if at least one of the surveys in capthist only has individuals of one sex. Any suggestions on how to fix this? The sex covariate is already coded as a factor with two levels (F and M).
Here code to reproduce the issue:
- Code: Select all
temptrap <- make.grid(nx = 6, ny = 6, spacing = 20, detector ="proximity")
capthist1<-sim.capthist (temptrap, detectpar = list(g0 = 0.2,sigma = 20))
capthist2<-sim.capthist (temptrap, detectpar = list(g0 = 0.2,sigma = 20))
covariates(capthist1)<-data.frame(sex=c("F","M")[rbinom(dim(capthist1)[1],1,0.5)+1])
covariates(capthist2)<-data.frame(sex=rep("M",dim(capthist2)[1]))
capthist<-MS.capthist(capthist1,capthist2)
secr.fit(capthist,hcov="sex")
secr.fit(capthist)
Thanks,
Mathias