# NOT RUN {
data(abdat)
param <- log(c(r= 0.42,K=9400,Binit=3400,sigma=0.05))
optmod <- nlm(f=negLLP,p=param,funk=simpspm,initpar=param,
notfixed=c(1,2,3,4),indat=abdat,logobs=log(abdat$cpue))
outfit(optmod,backtran= TRUE) #backtran=TRUE is default anyway
rval <- seq(0.325,0.45,0.0125) # set up the test sequence
columns <- c("r","K","Binit","sigma","-veLL")
result <- matrix(0,nrow=11,ncol=5,dimnames=list(rval,columns))
profest <- c(r= 0.32,K=11500,Binit=4250,sigma=0.05) # end of sequence
for (i in 1:11) {
param <- log(c(rval[i],profest[2:4])) #recycle the profest values to
parinit <- param # improve the stability of nlm as the r value
bestmodP <- nlm(f=negLLP,p=param,funk=simpspm,initpar=parinit, #changes
indat=abdat,logobs=log(abdat$cpue),notfixed=c(2:4))
bestest <- exp(bestmodP$estimate)
result[i,] <- c(bestest,bestmodP$minimum) # store each result
}
result #Now you can plot -veLL againt r values for the profile
# parset()
# plot(result[,"r"],result[,"-veLL"],type="l",lwd=2,panel.first=grid())
# points(result[,"r"],result[,"-veLL"],pch=16,cex=1.1)
# }
Run the code above in your browser using DataLab