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

If statements for TMB parameters

Open ciallen opened this issue 6 years ago • 1 comments

I'm finding my file won't compile if I read in parameter vectors inside an if statement, and then write an equation using those parameters. Can TMB do this? Or is there a workaround so that you can read in different parameter options based on the model you are using?

Problem example: DATA_INTEGER(op); if(op==1) { PARAMETER_VECTOR( b_j ); PARAMETER_VECTOR( theta_z ); } Type zero_prob = 1 / (1 + exp(-theta_z(0))); //This produces and error in compilation

ciallen avatar Apr 03 '18 19:04 ciallen

You're correct that TMB does not allow you to have DATA or PARAMETER lines in an if-then statement. Instead, I recommend that you have these be the same across models, and then interpret the parameters differently for different models. Specifically, if you have a PARAMETER_VECTOR(b_j) then the length of vector supplied from the R terminal could be different between models.

James-Thorson avatar Apr 03 '18 19:04 James-Thorson