I've noticed unstable behavior of nlminb on some Linux systems. The problem can
be reproduced by compiling R-3.5.2 using gcc-8.2 and running the following
snippet:
f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
xhat <- rep(1, 10)
abs( opt$
e))$hessian
[,1][,2]
[1,] 1.00e-06 0
[2,] 0.00e+00 1648722
# RECOMPILING WITH THE SUGGESTED CHANGE GIVES CORRECT HESSIAN:
>
optim(xhat,f,hessian=TRUE,method="CG",control=list(parscale=parscale))$hessian
[,1][,2]
[1,] 1.01e-06