Dear unmarked users
Together with a colleague, I am simulating detection/nondetection data for a single species and within one season under various combinations of true psi (occupancy probability) and true p (detection probability) for different habitat types.
We then want to fit an occupancy model using the function occu() from unmarked. Habitat is a categorical covariate on occupancy and we would like to fit it as a random effects factor. For each combination of true psi and true p, we simulate several datasets (5 for the moment, later it will be more). In some simulation replicates, the model-fitting works very well, but in some I get either of the following 3 errors:
1.Error in solve.default(full) :
system is computationally singular: reciprocal condition number = 1.05845e-46
2.Error in solve.default(full) :
Lapack routine dgesv: system is exactly singular: U[1,1] = 0
3.Error in optim(starts, fn = tmb_mod$fn, gr = tmb_mod$gr, method = method,:
gradient in optim evaluated to length 1 not 3
I suspect errors 1 and 2 are somehow related and that error 3 refers to an optimization gradient used by TMB to find the MLE…?
I have tried to manipulate the initial values in order to be closer to the true values by setting the intercept inits to either 0.25 or 0.75 (depending on whether the true value is > 0.5 or < 0.5). I also set the initial value for the sd of the random effect to some value between 0.3 and 1 to avoid extremely small inits for sd, but this did not solve the problem, errors still keep occurring. I nevertheless believe the problem is related to the initial values because when I encounter an error and try to manipulate the inits manually, I always end up finding some inits that work for that simulated dataset. But I have not found a set of inits that would work for the entire simulation (i.e. for all combinations of true psi and p values and for all 5-100 simulation replicates of each of those combinations).
Does anybody know what it is that leads to these specific error messages and how I can avoid them?
Thank you in advance for any input. The code is below.
Best wishes
Gesa
Code & notes:
Function simOccFac() serves to simulate the dataset. It results in detection histories (1/0) for M sites and J=2 visits where sites are sampled from 5 different habitats. The simulation of the dataset is repeated if 1) there are no detections at all, 2) the species was detected during at all sites during all visits, or 3) not all habitats were sampled.
simrep <- 5 # number of simulation replicates
M <- 200 # number of sites
pvals <- seq(0.1, 0.4, 0.1) # levels of true psi and p to be tested
for(i in 1:length(pvals)){ # Loop over levels of psi
for(j in 1:length(pvals)){ # Loop over levels of p
cat(paste('\n*** Doing psi =', pvals[i], 'and p =', pvals[j], '***'))
for(k in 1:simrep){
repeat{
# simulate data set
dat <- simOccFac(M=M, J=2, mean.occupancy=pvals[i],
mean.detection=pvals[j],
nHab=5, range.HAB=4)
# conditions to retain dataset: at least 1 detection; at least 1 site with < 2 detections; all factor levels occur
if(sum(dat$y) > 0 & sum(dat$y) < 2*M & sum(table(dat$HAB)>0)==5){
break
}
}
# create unmarked dataframe
umf <- unmarkedFrameOccu(y=dat$y,
siteCovs=data.frame(habitat=as.factor(dat$HAB)))
# provide starting values
int <- c(qlogis(runif(1)), runif(1), # occupancy parameters: psi-intercept (mean), sd of random effect
qlogis(runif(1))) # detection parameters: p-intercept
# int <- c(qlogis(ifelse(pvals[i]<0.5, 0.25, 0.75)), runif(1, 0.3, 1),
# qlogis(ifelse(pvals[j]<0.5, 0.25, 0.75)))
# fit model
fm <- occu(~1 ~ (1|habitat), data=umf, starts=int, control=list(maxit=1000))
}
}
}
--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/804e268a-8ad6-48e8-beb1-0febe1a6dd03n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/c52240c3-d12e-4a3d-a424-10b86bb5a122n%40googlegroups.com.