`panel4pt1.fn` <- function(y,J=11,nsites=50,Nmax=100){ # This is the R construction of the likelihood for the Royle-Nichols # model (Panel 4.1), and R commands for obtaining the MLEs and summarizing # the output. #### lik<-function(parms){ r<-expit(parms[1]) lambda<-exp(parms[2]) pvec<-1-(1-r)^(0:Nmax) gN<-dpois(0:Nmax,lambda) gN<-gN/sum(gN) lik<-rep(NA,nsites) for(i in 1:nsites){ lik[i]<-sum(dbinom(y[i],J,pvec)*gN) } -1*sum(log(lik)) } #### tmp<-nlm(lik,c(0,0),hessian=TRUE) ests<-tmp$estimate aic<-tmp$minimum*2 + 2*length(ests) se<- sqrt(diag(solve(tmp$hessian))) list(ests=ests,se=se,aic=aic) }