template(file = NULL)Macros to read data and declare parameters:
| Template Syntax | C++ type |
| R type | DATA_VECTOR(name) |
| vector |
vector |
| DATA_MATRIX(name) | matrix |
| matrix | DATA_SCALAR(name) |
| Type | numeric(1) |
| DATA_INTEGER(name) | int |
| integer(1) | DATA_FACTOR(name) |
| vector |
factor |
| DATA_IVECTOR(name) | vector |
| integer | DATA_SPARSE_MATRIX(name) |
| Eigen::SparseMatrix |
dgTMatrix |
| DATA_ARRAY(name) | array |
| array | PARAMETER_MATRIX(name) |
| matrix |
matrix |
| PARAMETER_VECTOR(name) | vector |
| vector | PARAMETER_ARRAY(name) |
| array |
array |
| PARAMETER(name) | Type |
| numeric(1) | Template Syntax |
Basic calculations:
| Template Syntax |
| Explanation |
| REPORT(x) |
| Report x back to R |
| ADREPORT(x) |
| Report x back to R with derivatives |
|
vector |
| R equivalent of v=numeric(n1) |
|
matrix |
| R equivalent of m=matrix(0,n1,n2) |
|
array |
| R equivalent of a=array(0,c(n1,n2,n3)) |
| v+v,v-v,v*v,v/v |
| Pointwise binary operations |
| m*v |
| Matrix-vector multiply |
| a.col(i) |
| R equivalent of a[,,i] |
| a.col(i).col(j) |
| R equivalent of a[,j,i] |
| a(i,j,k) |
| R equivalent of a[i,j,k] |
| exp(v) |
| Pointwise math |
| m(i,j) |
| R equivalent of m[i,j] |
| v.sum() |
| R equivalent of sum(v) |
| m.transpose() |
| R equivalent of t(m) |
Some distributions are available as C++ templates with syntax close to R's distributions:
| Function header |
| Distribution |
| dnbinom2(x,mu,var,int give_log=0) |
| Negative binomial with mean and variance |
| dpois(x,lambda,int give_log=0) |
| Poisson distribution as in R |
| dlgamma(y,shape,scale,int give_log=0) |
| log-gamma distribution |
| dnorm(x,mean,sd,int give_log=0) |
| Normal distribution as in R |