library(RTMB) turbot <- read.table("turbot.dat", head=FALSE) dat <- list(pos=turbot[,2], catch=turbot[,3], N00=3529, w=4.5, t=2) par <- list(alpha=0, logSigma=5, logitQ=0) l <- function(par){ getAll(par,dat) # now we can directly access everything in the two lists sd <- exp(logSigma)*sqrt(t) q <- plogis(logitQ) C.bar <- q*N00*(pnorm((pos+w/2-alpha*t)/sd)-pnorm((pos-w/2-alpha*t)/sd)) ADREPORT(sd) # notice these additions ADREPORT(q) # ADREPORT(C.bar) # REPORT(C.bar) # -sum(dpois(catch, C.bar, log=TRUE)) } obj <- MakeADFun(l,par,silent=TRUE) fit <- nlminb(obj$par,obj$fn, obj$gr) rep <- obj$report() # extract list of reported quantities sdrep <- sdreport(obj) # extract estimates and Hessian-based and delta approximated sd pl <- as.list(sdrep, what="Est") # format parameter etimates as list of initials plsd <- as.list(sdrep, what="Std") # format sd of parameter estimates as list of initials plr <- as.list(sdrep, what="Est", report=TRUE) # format to list of AD reported quantities plrsd <- as.list(sdrep, what="Std", report=TRUE) # format to list of delta approx sd of AD reported quantities