Introduction
Recall that, in this model, we assume that we only have unmarked individuals. In other words, we only know the total number of individuals seen in each trap and each occasion. For the moment being, we will assume that we know the overall number of individuals that are present. The goal is to show that this model struggles to converge even in this very optimistic scenario because of identifiability issues regarding estimating the individual parameters \(\lambda_0\) and \(\sigma^2\) as well as the center of each activity center.
Before we jump in, recall that:
\[n_j =\sum_{i=1}^n \sum_{k=1}^k z_{ijk} \sim Poisson(K \times \sum_{i=1}^n \lambda_{ij}) \]
where \(n_j\) is the number of individuals in trap \(j\). This is going to be the main expression in our SCR model.
Simulating data for model 2
Here is how we simulate data for this model.
rm(list=ls())
# library('proxy')
library('ggplot2')
set.seed(1)
#parameter values
=20
sig2=8
lambda0
#number of unmarked individuals
=10
nind
#spatial extent
=ymax=100
xmax
#coordinates of activity center
=data.frame(x=runif(nind,min=0,max=xmax),
coord.acentery=runif(nind,min=0,max=ymax))
#traps and their coordinates
=25 #number of traps
ntraps=seq(from=1,to=xmax,length.out=5)
tmp=expand.grid(x=tmp,
coord.trapsy=tmp)
#encounter times
=5
ntimes
#calculate distances
=matrix(NA,ntraps,nind)
dist1for (j in 1:ntraps){
for (i in 1:nind){
=(coord.traps$x[j]-coord.acenter$x[i])^2
x2=(coord.traps$y[j]-coord.acenter$y[i])^2
y2=sqrt(x2+y2)
dist1[j,i]
}
}# dist1a=proxy::dist(x=coord.traps,y=coord.acenter)
# unique(dist1-dist1a)
#generate z
=matrix(NA,ntraps,ntimes)
n=array(NA,dim=c(nind,ntraps,ntimes))
zarrayfor (t1 in 1:ntimes){
=matrix(NA,ntraps,nind)
zfor (i in 1:nind){
=exp(-dist1[,i]/sig2)
g=rpois(ntraps,lambda0*g)
z[,i]=z[,i]
zarray[i,,t1]
}=apply(z,1,sum)
n[,t1]
}
#sum over time steps
=apply(n,1,sum)
N$N=N
coord.trapsggplot()+
geom_tile(data=coord.traps,aes(x=x,y=y,fill=N))+
geom_point(data=coord.acenter,aes(x=x,y=y),col='red')
Estimating parameters
To estimate the model parameters, we rely on the code below
library('jagsUI')
# MCMC settings
<- 10000 #number of iterations
ni <- 5 #interval to thin
nt <- 5000 #number of iterations to discard as burn-in
nb <- 3 #number of chains
nc
#parameters to monitor
=c('lambda0','sig2','coord.acenter')
params
#basic settings
=nrow(coord.traps); #ntraps;
ntraps=10
nind=coord.traps$N
nvec=list(nvec=nvec,coord.trap=coord.traps,
dat1nind=nind,ntimes=ntimes,ntraps=ntraps)
#run JAGS
setwd('U:\\uf\\courses\\bayesian course\\group activities\\17 example scr\\mod2')
=jags(model.file="unmarked JAGS.R",
model2parameters.to.save=params,data=dat1,
n.chains=nc,n.burnin=nb,n.iter=ni,n.thin=nt,DIC=TRUE,
verbose=F)
summary(model2) #the Rhat results suggest that the algorithm has converged
## Summary for model 'unmarked JAGS.R'
## Saved parameters: lambda0 sig2 coord.acenter deviance
## MCMC ran for 0.429 minutes at time 2022-06-15 14:16:08.
##
## For each of 3 chains:
## Adaptation: 100 iterations (sufficient)
## Burn-in: 5000 iterations
## Thin rate: 5 iterations
## Total chain length: 10100 iterations
## Posterior sample size: 1000 draws
##
## **WARNING** Rhat values indicate convergence failure.
##
## DIC info: (pD = var(deviance)/2)
## pD = 22.2 and DIC = 189.143
# model2
#look at model parameters
plot(model2$sims.list$lambda0,type='l',ylab='lambda0',xlab='iterations')
abline(h=8,col='red')
plot(model2$sims.list$sig2,type='l',ylab='sigma2',xlab='iterations')
abline(h=20,col='red')
Notice that we have increased the number of iterations relative to what we used for model 1 and we are still having a hard time making the model converge even though we are assuming, rather optimistically, that the overall number of individuals is known. This is partly because we have a very strong correlation between \(\lambda_0\) and \(\sigma^2\).
#look at correlation between these parameters
plot(model2$sims.list$lambda0,model2$sims.list$sig2,
ylab='sigma2',xlab='lambda0')
Furthermore, if you look at the Rhat and n.eff values for the coordinates of the activity centers, you will see a lot of issues there as well. This makes sense. You can probably tell that there are more activity centers in certain areas but not in others just based on which traps had more individuals. However, because none of the individuals are marked, you cannot tell to which individuals these activity centers belong to.
#look at Rhat and n.eff
model2
## JAGS output for model 'unmarked JAGS.R', generated by jagsUI.
## Estimates based on 3 chains of 10000 iterations,
## adaptation = 100 iterations (sufficient),
## burn-in = 5000 iterations and thin rate = 5,
## yielding 3000 total samples from the joint posterior.
## MCMC ran for 0.429 minutes at time 2022-06-15 14:16:08.
##
## mean sd 2.5% 50% 97.5% overlap0 f Rhat
## lambda0 7.743 1.510 5.221 7.629 11.020 FALSE 1 1.024
## sig2 20.909 2.728 16.317 20.654 26.790 FALSE 1 1.029
## coord.acenter[1,1] 57.556 31.574 1.920 67.272 98.220 FALSE 1 1.308
## coord.acenter[2,1] 69.322 24.775 6.928 75.092 98.621 FALSE 1 1.097
## coord.acenter[3,1] 64.885 28.217 5.012 72.850 98.730 FALSE 1 1.100
## coord.acenter[4,1] 50.910 32.846 1.584 60.160 97.329 FALSE 1 1.026
## coord.acenter[5,1] 44.914 32.799 1.141 36.529 96.464 FALSE 1 1.010
## coord.acenter[6,1] 53.602 32.130 2.248 62.562 98.038 FALSE 1 1.072
## coord.acenter[7,1] 51.974 31.770 1.997 60.832 97.778 FALSE 1 1.144
## coord.acenter[8,1] 62.220 29.710 2.603 71.968 98.406 FALSE 1 1.084
## coord.acenter[9,1] 61.892 29.214 4.980 71.272 98.030 FALSE 1 1.027
## coord.acenter[10,1] 61.449 31.002 2.025 71.145 98.415 FALSE 1 1.101
## coord.acenter[1,2] 54.983 25.205 10.051 56.981 96.284 FALSE 1 1.106
## coord.acenter[2,2] 54.713 25.999 13.068 50.765 98.055 FALSE 1 1.022
## coord.acenter[3,2] 51.503 25.187 10.209 47.551 96.562 FALSE 1 1.009
## coord.acenter[4,2] 57.809 25.635 10.352 65.285 97.329 FALSE 1 1.099
## coord.acenter[5,2] 55.804 27.076 6.873 65.516 96.095 FALSE 1 1.011
## coord.acenter[6,2] 54.256 26.622 9.137 58.895 96.674 FALSE 1 1.019
## coord.acenter[7,2] 51.214 27.962 7.148 51.908 96.580 FALSE 1 1.068
## coord.acenter[8,2] 55.854 25.466 10.404 58.317 97.244 FALSE 1 1.005
## coord.acenter[9,2] 52.367 26.919 8.049 49.223 97.139 FALSE 1 1.051
## coord.acenter[10,2] 58.408 24.661 18.078 62.411 98.122 FALSE 1 1.026
## deviance 166.931 6.716 155.554 166.141 182.070 FALSE 1 1.017
## n.eff
## lambda0 146
## sig2 109
## coord.acenter[1,1] 11
## coord.acenter[2,1] 43
## coord.acenter[3,1] 33
## coord.acenter[4,1] 86
## coord.acenter[5,1] 223
## coord.acenter[6,1] 33
## coord.acenter[7,1] 18
## coord.acenter[8,1] 31
## coord.acenter[9,1] 92
## coord.acenter[10,1] 29
## coord.acenter[1,2] 24
## coord.acenter[2,2] 94
## coord.acenter[3,2] 234
## coord.acenter[4,2] 27
## coord.acenter[5,2] 225
## coord.acenter[6,2] 112
## coord.acenter[7,2] 35
## coord.acenter[8,2] 374
## coord.acenter[9,2] 44
## coord.acenter[10,2] 81
## deviance 128
##
## **WARNING** Rhat values indicate convergence failure.
## Rhat is the potential scale reduction factor (at convergence, Rhat=1).
## For each parameter, n.eff is a crude measure of effective sample size.
##
## overlap0 checks if 0 falls in the parameter's 95% credible interval.
## f is the proportion of the posterior with the same sign as the mean;
## i.e., our confidence that the parameter is positive or negative.
##
## DIC info: (pD = var(deviance)/2)
## pD = 22.2 and DIC = 189.143
## DIC is an estimate of expected predictive error (lower is better).
Comments?
Send me an email at