`panel11pt5.fn` <- function(){ library("R2WinBUGS") #R script to fit CJS model with transients in WinBUGS. This is a simple model #with year-specific detection and survival probabilities and a constant #residency probability. Requires data file 'mapsdata.list' which can be #sourced into your R workspace. if(!exists("mapsdata.list")){ cat("data file: mapsdata.list not found",fill=TRUE) return(NULL) } cat(" model { for(t in 1:(nyear-2)){ phi0[t]~dunif(0,1) lphi0[t]<-log(phi0[t]/(1-phi0[t])) p[t]~dunif(0,1) p2[t+1]<-p[t] } p2[1]<-1; p2[nyear]<-1 phi0[nyear-1]~dunif(0,1) lphi0[nyear-1]<-log(phi0[nyear-1]/(1-phi0[nyear-1])) pi~dunif(0,1) tau~dunif(0,1) for(i in 1:nind){ R[i]~dbern(pi) mm[i]<-R[i]*tau resident[i]~dbern(mm[i]) z[i,first[i]]~dbern(1) for(j in (first[i]+1):nyear){ logit(phi[i,j-1])<- lphi0[j-1] muy[i,j]<-p2[j]*z[i,j] y[i,j]~dbern(muy[i,j]) muz[i,j]<-z[i,j-1]*phi[i,j-1]*R[i] z[i,j]~dbern(muz[i,j]) } } }",fill=TRUE,file="model.txt") y<-mapsdata.list$y first<-mapsdata.list$first nind<-mapsdata.list$nind nyear<-mapsdata.list$nyear # resident is the predetermined residents indicator resident<-mapsdata.list$resident Zst<-y for(i in 1:nind){ Zst[i,first[i]:last[i]]<-1 if(first[i]>1){ Zst[i,1:(first[i]-1)]<-NA } } data <- list ("y","first","nind","nyear","resident") inits <- function(){ list ( phi0=runif(nyear-1),p=runif(nyear-2,.2,.6),z=Zst) } parameters <- c("phi0","p","pi","tau") out <- bugs (data, inits, parameters, "model.txt", n.thin=2,n.chains=2, n.burnin=1000,n.iter=2000,debug=TRUE) return(out) }