|
Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
|
Random draws for composition-style observations, used by SIMULATE. More...
Go to the source code of this file.
Functions | |
| template<class Type> | |
| vector< Type > | rmultinom_rce (Type N, vector< Type > p) |
| Draw multinomial counts by sequential conditional binomials. | |
| template<class Type> | |
| vector< Type > | rdirichlet_rce (vector< Type > alpha) |
| Draw Dirichlet proportions as normalized independent gammas. | |
| template<class Type> | |
| vector< Type > | rdirmultinom_rce (Type N, vector< Type > alpha) |
| Draw Dirichlet-multinomial counts. | |
Random draws for composition-style observations, used by SIMULATE.
Every composition likelihood in the model – age/length comps, conditional age-at-length, and stomach contents – is a multinomial or a Dirichlet-multinomial over a vector of bins, and TMB supplies neither draw: distributions_R.hpp stops at univariate generators (rbinom, rgamma, runif, ...). These are the two multivariate draws built from them, both the standard constructions and exact given N and p, with N rounded to a whole count the only approximation either makes:
Both return COUNTS summing to N, as the densities in helper_functions.hpp and comp_osa.hpp read them; the caller converts back to its data object's scale. They run only inside SIMULATE{}, where Type is always double and there is no AD tape, so CppAD::Integer() and the R generators underneath are safe.
Definition in file comp_sim.hpp.
| vector< Type > rdirichlet_rce | ( | vector< Type > | alpha | ) |
Draw Dirichlet proportions as normalized independent gammas.
With a very small concentration every gamma can underflow to zero in double precision, leaving nothing to normalize; onset is around sum(alpha) below 1e-3. The limit of a Dirichlet as alpha -> 0 is degenerate – all the mass in ONE bin, chosen with probability proportional to alpha – so that is what is returned. A flat vector would be the opposite of the near-degenerate composition the parameters describe, turning a concentrated diet into a diffuse one.
| alpha | Concentration parameters, one per bin, non-negative. |
Definition at line 88 of file comp_sim.hpp.
Referenced by rdirmultinom_rce().
| vector< Type > rdirmultinom_rce | ( | Type | N, |
| vector< Type > | alpha ) |
Draw Dirichlet-multinomial counts.
| N | Number of observations to place. |
| alpha | Concentration parameters, one per bin; here predicted proportion * N * theta. The draw reproduces the MEAN the density predicts but not every moment of it: the density is evaluated on offset data while the draw is on the raw scale. |
Definition at line 128 of file comp_sim.hpp.
References rdirichlet_rce(), and rmultinom_rce().
| vector< Type > rmultinom_rce | ( | Type | N, |
| vector< Type > | p ) |
Draw multinomial counts by sequential conditional binomials.
| N | Number of observations to place. Rounded to a whole number, as the binomial size must be an integer; effective sample sizes reaching here are whole counts (stomachs sampled, fish aged) or a weighting of them. |
| p | Bin probabilities. Rescaled internally, so they need not sum to 1, but must be non-negative. |
Definition at line 41 of file comp_sim.hpp.
Referenced by rdirmultinom_rce().