R code for single season single species models?

Hi everyone; are R codes for the single season single species models available? I was urged by my supervisor to move away from the comfi Presence interface ...



Analysis Forum
http://www.phidot.org/forum/
# single-season occupancy model using Blue Ridge Salamander data
a=c(0,0,0,1,1,
0,1,0,0,0,
0,1,0,0,0,
1,1,1,1,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
1,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
1,0,0,1,1,
1,0,1,1,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,1,0,
0,0,0,1,0,
0,0,0,0,1,
0,0,0,0,1);
n=length(a)/5; dim(a)=c(5,n); b=t(a); eps=.0000000000000001;
lik <- function(th) { # likelihood function - th=parameter vector
lik=0; psi=1/(1+exp(-th[1])); p=c(0,0);
p[2]=1/(1+exp(-th[2])); p[1]=1-p[2];
for (i in 1:n) { # loop through n sites
prd=psi*prod(p[1+b[i,]]); # det. hist prob. = product(psi*pq(j))
if (sum(b[i,])<1) prd=prd+1-psi; # where pq(j)=p if detected in survey j
lik=lik+log(prd) # pq(j)=1-p if not detected in j
}
return(-lik)
}
out <- nlm(lik,c(0.1,0.2),hessian=T,print.level=0) # find max likelihood value
beta=out$estimate; vc=solve(out$hessian); # = min neg. likelihood value
print(out); cat("SE(theta)="); print(sqrt(diag(vc)))
psi=1/(1+exp(-beta[1])); p=1/(1+exp(-beta[2]));
d=exp(-beta[1])*psi*psi; sepsi=sqrt(d*vc[1,1]*d); # get se(psi) via delta method
d=exp(-beta[2])*p*p; sep=sqrt(d*vc[2,2]*d); #
cat(c("psi=",psi," se=",sepsi,"\n"));
cat(c("p=",p," se=",sep,"\n"));