kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
178 stars 81 forks source link

Better default behavior for `bias.correct=TRUE` without random effects #403

Open James-Thorson-NOAA opened 1 week ago

James-Thorson-NOAA commented 1 week ago

Description:

Better default behavior for sdreport when using bias.correct=TRUE without any random effects

Reproducible Steps:

In tinyVAST, users get a cryptic error when using bias.correct=TRUE in a model without random effects. This can be traced to default behavior in sdreport as shown here:

library(RTMB)
Y = rnorm(n=10)

nll = function(p) -1*sum(dnorm(Y,mean=p$mu,sd=p$sd,log=TRUE))
obj = MakeADFun(nll, parameters=list(mu=0,sd=1))
opt = nlminb( obj$par, obj$fn, obj$gr )
sdrep = sdreport( obj, bias.correct=TRUE )

Current Output:

Error in obj$env$spHess(random = TRUE) : attempt to apply non-function

Expected Output:

Personally, I think it might be nice to have an informative error in sdreport, or even just replacing the epsilon-method output with standard delta-method output in the absence of any random effects (which is presumably what is intended by the estimator in that instance).

TMB Version:

‘1.9.15’

R Version:

4.4.1

Operating System:

Windows