model { # sample inclusion probability for data augmentation psi~dunif(0,1) # movement parameters sigma1~dunif(0,10) sigma2~dunif(0,10) tau1<-1/(sigma1*sigma1) tau2<-1/(sigma2*sigma2) # detection probability given animal is within area D p~dunif(0,1) #fudge represents the distance from the sampling unit that animals might be coming from #i.e. it defines the state-space for the animals - delta must be provided as data fudge<-delta*sigma Xlfudge<-Xl-fudge Xufudge<-Xu+fudge Ylfudge<-Yl-fudge Yufudge<-Yu+fudge for(i in 1:(nind+nzeroes)){ # inclusion indicator z[i]~dbin(psi,1) #animal home range centers s1[i]~dunif(Xl,Xu) s2[i]~dunif(Yl,Yu) #obtainig the number of animals with home range centers inside D (which actually are real animals, i.e. z[i]=1) flag1S[i]<-step(s1[i]-(Xl+fudge)) flag2S[i]<- step( (Xu-fudge) - s1[i]) flag3S[i]<- step(s2[i] - (Yl+fudge)) flag4S[i]<- step( (Yu-fudge)-s2[i]) inDS[i]<-flag1S[i]*flag2S[i]*flag3S[i]*flag4S[i]*z[i] for(t in 1:T){ # compute whether individual is in plot at t flag1[i,t]<-step(U1[i,t]-(Xl+fudge)) flag2[i,t]<- step( (Xu-fudge) - U1[i,t]) flag3[i,t]<- step(U2[i,t] - (Yl+fudge)) flag4[i,t]<- step( (Yu-fudge)-U2[i,t]) inplot[i,t]<-flag1[i,t]*flag2[i,t]*flag3[i,t]*flag4[i,t] # if a member of population and inplot, then subject to sampling mu[i,t]<-inplot[i,t]*z[i]*p #actual location of animal by occasion U1[i,t]~dnorm(s1[i],tau1)I(Xlfudge,Xufudge) U2[i,t]~dnorm(s2[i],tau2)I(Ylfudge,Yufudge) Y[i,t]~dbern(mu[i,t]) } } #obtainig the number of animals with home range centers inside S N<-sum(z[1:nind+nzeroes]) #obtainig the number of animals with home range centers inside D ND<-sum(inDS[1:nind+nzeroes]) }