2018_FSH556 icon indicating copy to clipboard operation
2018_FSH556 copied to clipboard

Gamma model

Open klomori opened this issue 6 years ago • 9 comments

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

klomori avatar Apr 02 '18 16:04 klomori

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.

SOUKETU avatar Apr 02 '18 21:04 SOUKETU

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"

klomori avatar Apr 02 '18 22:04 klomori

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 .

James-Thorson avatar Apr 02 '18 22:04 James-Thorson

Thanks. That fixed the warning message from the compile step, but I am still getting the Error message in the MakeADFUN.

klomori avatar Apr 02 '18 22:04 klomori

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 .

James-Thorson avatar Apr 02 '18 22:04 James-Thorson

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'

klomori avatar Apr 04 '18 14:04 klomori

OK, so you have two issues:

  1. 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 and shape_i and jnll_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.

  2. 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 the Opt$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.

James-Thorson avatar Apr 04 '18 14:04 James-Thorson

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.

SOUKETU avatar Apr 04 '18 15:04 SOUKETU

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 .

klomori avatar Apr 04 '18 15:04 klomori