2018_FSH556
2018_FSH556 copied to clipboard
Gamma model
I am trying to run the delta-gamma model separately to make sure it runs, but am running into errors (warning errors when I compile the template file). My gamma equation is similar to the one Jim posted, except I replaced CV with sd/x-bar. Here's the dgamma code: dgamma( y_i(i), pow((logsd/linpred_i(i)),-2), linpred_i(i)*pow((logsd/linpred_i(i)),-2), true )
Is anyone else running into this problem? or know how to resolve it? Thanks! Kristen
Could you post the warning messages? Two things regarding your parameterization: 1) for the scale parameter, you should have 2 instead of -2; 2) perhaps check if your linpred_i is in log space. But, it's not likely these would cause complier errors.
Here is the warning inside the compile log: C:/Users/komori/DOCUME~1/R/WIN-LI~1/3.4/TMB/include/tmb_core.hpp:1330:7: required from here HW1_tempgamma.cpp:29:19: warning: value computed is not used [-Wunused-value] if(y_i(i)!=0) log( 1-zero_prob ) + dgamma( y_i(i), pow((logsd/linpred_i(i)),-2), linpred_i(i)*pow((logsd/linpred_i(i)),2), true );
And here is the warning message from the MakeADFun(...) function: Error in .Call("getParameterOrder", data, parameters, new.env(), PACKAGE = DLL) : "getParameterOrder" not available for .Call() for package "HW1_tempgamma.cpp"
You're missing the equals symbol and the variable on the left of it. So the compiler doesn't understand what you want to do with that expression.
On Mon, Apr 2, 2018, 3:24 PM klomori [email protected] wrote:
Here is the warning inside the compile log: C:/Users/komori/DOCUME1/R/WIN-LI1/3.4/TMB/include/tmb_core.hpp:1330:7: required from here HW1_tempgamma.cpp:29:19: warning: value computed is not used [-Wunused-value] if(y_i(i)!=0) log( 1-zero_prob ) + dgamma( y_i(i), pow((logsd/linpred_i(i)),-2), linpred_i(i)*pow((logsd/linpred_i(i)),2), true );
And here is the warning message from the MakeADFun(...) function: Error in .Call("getParameterOrder", data, parameters, new.env(), PACKAGE = DLL) : "getParameterOrder" not available for .Call() for package "HW1_tempgamma.cpp"
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/James-Thorson/2018_FSH556/issues/1#issuecomment-378065550, or mute the thread https://github.com/notifications/unsubscribe-auth/AHnqTVY1iuU7-969NNVuxcJnsvVO4RJoks5tkqUdgaJpZM4TDuW4 .
Thanks. That fixed the warning message from the compile step, but I am still getting the Error message in the MakeADFUN.
In general, I think the best solution is to go back to code that you know is working and make changes one at a time to identify what change led to the error. Are you willing to try that for a bit and then I could look?
On Mon, Apr 2, 2018, 3:36 PM klomori [email protected] wrote:
Thanks. That fixed the warning message from the compile step, but I am still getting the Error message in the MakeADFUN.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/James-Thorson/2018_FSH556/issues/1#issuecomment-378068387, or mute the thread https://github.com/notifications/unsubscribe-auth/AHnqTVqkTlfWobIfUXG76SIkanj6l04Oks5tkqf9gaJpZM4TDuW4 .
I am still running into issues with my gamma model. The model appears to be compiling correctly (and both the mean and sd are in the same space), but am unable to optimize/ solve it.
The error output from R is: Error in solve.default(h, g) : system is computationally singular: reciprocal condition number = 3.78274e-17 In addition: There were 50 or more warnings (use warnings() to see the first 50)
And the warning messages are: 50: In f(x, order = 0) : value out of range in 'lgamma'
OK, so you have two issues:
-
warning message "50: In f(x, order = 0) : value out of range in 'lgamma'" -- I recommend dividing your calculations into many smaller pieces, and using REPORT to inspect each intermediate calculation. So perhaps start by making vectors
scale_i
andshape_i
andjnll_i
for each observation i and using REPORT to extract them to confirm that shape and scale are always positive and and jnll_i is the same value as you're getting from identical calculations on the R side. -
Error in solve.default(h, g) : system is computationally singular: reciprocal condition number = 3.78274e-17: This is a good issue to bring up, and it occurs whenever the hessian matrix (matrix of 2nd derivatives around your MLE) is not positive definite and therefore cannot be inverted. This usually occurs because some parameter has a gradient of zero at the MLE, i.e., because it is not being used in the likelihood calculation. Please try running
Opt = TMBhelper::Optimize(obj=Obj, getsd=FALSE)
where...
is the other inputs, and inspect theOpt$diagnostics
slot to see if any parameter has gradient of zero. If this doesn't fix it, then I'll take a look at your code.
I just took a quick look at your codes. It seems like you include temperature as a covariate in the model. There're missing values in temp (-9999.0). This can potentially cause the errors you've seen. If you can run the model without temp but not with temp, it's likely due to the covariate.
Thanks! Running the model without the covariate makes the warning messages disappear and I able to resolve the other error message by looking at the jnn_i's .