`table10pt2.fn` <- function(ni=3000,nb=2000,nthin=1,nchain=3,nz=160){ # Jolly-Seber Model - Schwarz-Arnason parameterization by data augmentation. # This R script and model produced the results in Table 10.2. library("R2WinBUGS") y<-dipper.data\$y y[is.na(y)]<-0 y<-rbind(y,matrix(rep(0,ncol(y)*nz),ncol=ncol(y),byrow=TRUE)) M<-nrow(y) T<-ncol(y) z<-y sink("jsmodel.txt") cat(" model { for(j in 1:(T-1)){ phi0[j]~dunif(0,1) lphi[j]<-log(phi0[j]/(1-phi0[j])) } psi~dunif(0,1) # arbitrary constrains on p[] ptmp[1]<- 1 ptmp[T]<- 1 for(i in 2:(T-1)){ p[i]~dunif(0,1) ptmp[i]<-p[i] } for(j in 1:M){ for(i in 1:(T-1)){ logit(phi[j,i])<-lphi[i] } } # Dirichlet prior for entrance probabilities for(i in 1:T){ beta[i]~dgamma(1,1) gamma[i]<-beta[i]/sum(beta[1:T]) } # convert entrance probs to conditional entrance probs # the number of individuals recruited is a probability, expressed # relative to individuals in the super-population of size sum(w[1:M]) # that have not yet recruited. cprob[1]<-gamma[1] for(j in 2:T){ cprob[j]<-gamma[j]/(1-sum(gamma[1:(j-1)])) } for(i in 1:M){ w[i]~dbin(psi,1) z[i,1]~dbin(gamma[1],1) mu[i]<-z[i,1]*ptmp[1]*w[i] y[i,1]~dbin(mu[i],1) recruitable[i,1]<-1-z[i,1] for(j in 2:T){ part1[i,j]<- phi[i,j-1]*z[i,j-1] recruitable[i,j]<- recruitable[i,(j-1)]*(1-z[i,j]) muz[i,j]<- part1[i,j] + cprob[j]*recruitable[i,j-1] z[i,j]~dbin(muz[i,j],1) muy[i,j]<-z[i,j]*ptmp[j]*w[i] y[i,j]~dbin(muy[i,j],1) } } for(i in 1:T){ N[i]<-inprod(z[1:M,i],w[1:M]) } Nsuper<-sum(w[1:M]) } ",fill=TRUE) sink() data <- list ("y","M","T") inits <- function(){ list (psi=runif(1), w=rbinom(M,1,.5), phi0=runif(T-1,.2,.9), z=z) } parameters <- c("psi","p","phi0","N","Nsuper","gamma") out <- bugs (data, inits, parameters, "jsmodel.txt", n.thin=nthin,n.chains=nchain, n.burnin=nb,n.iter=ni,debug=TRUE) return(out) }