Error in nlminb : NA/NaN gradient evaluation

313 views
Skip to first unread message

Guillaume

unread,
Jul 7, 2023, 11:32:41 AM7/7/23
to TMB Users

Hello,

I’m trying to build a model using TMB, but encountered some problems. When calling MakeADFun, the function returns NaN values and I can’t find out how to fix that. I tried a version with using dnorm instead of MVN and without random effects, that seems to work, but switching back one of these two things makes the problem reappear.

If anyone could help me that would be greatly appreciated. Thanks,

Guillaume Derringer

scenario2.R

Cole Monnahan - NOAA Federal

unread,
Jul 10, 2023, 11:49:23 AM7/10/23
to TMB Users
I didn't really look at the model much but when I ran it I saw that the NLL started at around 700 but then went to a huge negative number until something broke. This appears to be because you have the wrong sign for the RE probabilities

 res_comp(2)+=sum(dnorm(temp,0,u_cov(t-1,t-1),true));} //difference with initial model

      res_comp(2) -= dnbinom2( Y(i), mean_y, var_y, 1 );

So in the first you're calculating the log-density and the second one the negative log-likelihood, but then summing them together which creates havoc. 

Set the += to -= and see if that works. I also suggest putting it into res_comp(1) so you can look at them separately in the report()

Reply all
Reply to author
Forward
0 new messages