5 R style probability distributions

Attempts have been made to make the interface (function name and arguments) as close as possible to that of R.

  • The densities (d...) are provided both in the discrete and continuous case, cumulative distributions (p...) and inverse cumulative distributions (q...) are provided only for continuous distributions.

  • Scalar and vector arguments (in combination) are supported, but not array or matrix arguments.

  • The last argument (of type int) corresponds to the log argument in R: 1=logaritm, 0=ordinary scale. true (logaritm) and false (ordinary scale) can also be used.

  • Vector arguments must all be of the same length (no recycling of elements). If vectors of different lengths are used an “out of range” error will occur, which can be picked up by the debugger.

  • DATA_IVECTOR() and DATA_INTEGER() cannot be used with probability distributions, except possibly for the last (log) argument.

  • An example:

    DATA_SCALAR(y);
    DATA_VECTOR(x);
    vector<Type> rate(10);
    matrix<Type> rate_matrix(10, 10);
    dexp(y, rate, true);                    // OK, returns vector of length 10 of log-densities
    dexp(x, rate, true);                    // OK if x is length 10
    dexp(x, rate_matrix, true);             // Error, matrix arguments not allowed
  • To sum over elements in the vector returned use

    sum(dexp(x,rate));