Programming bits�(The “if” statement)
if (condition)
Statements-1;
else
Statements-2;
{ statement; statement; }
Constructing conditions
== Equal to (NOT =)
<= Less than or equal to
>= Greater than or equal to
< Less than
> Greater than
!= Not equal to
&& Condition is true if both sub-conditions are true
|| Condition is true if one of the sub-conditions is true
! Condition is true if sub-condition is false
The “for” statement
for (initial state; terminal condition; increment)
{ statements; }
biomass(1) = 1;
for (year=0; year<nyear; year++)
biomass(year+1)=biomass(year)*r;
Vector & matrix functions
http://kaskr.github.io/adcomp/matrix_arrays_8cpp-example.html
Extracting from arrays and matrices:
vector = matrix.col(index)
vector = matrix.row(index)
vector = matrix.diagonal();
Subvectors: extract a subset of a vector:
vector2 = vector1(index1,index2)
NB: arrays start at 0, so index1=2 is element 3!
TMBhelper package
devtools::install_github("kaskr/TMB_contrib_R/TMBhelper")
https://github.com/kaskr/TMB_contrib_R
(includes TMBphase to do phased estimation a la ADMB, and TMBdebug)
TMB Rstudio integration & code chunks
Some helpful code chunks:
https://github.com/kaskr/adcomp/wiki/Code--snippets
For Rstudio tmb snippets, and static code analyzer & more, use:
TMB:::setupRStudio()
Then restart Rstudio.