9.3 Calling Functions
All function arguments are mandatory—there are no default values.
Functions as Expressions
Functions with non-void return types are called just like any other built-in function in Stan—they are applied to appropriately typed arguments to produce an expression, which has a value when executed.
Functions as Statements
Functions with void return types may be applied to arguments and used as statements. These act like sampling statements or print statements. Such uses are only appropriate for functions that act through side effects, such as incrementing the log probability accumulator, printing, or raising exceptions.
Probability Functions in Sampling Statements
Functions whose name ends in _lpdf
or _lpmf
(density and mass functions) may be used as probability functions and may be used in place of parameterized distributions on the right-hand-side of sampling statements. There is no restriction on where such functions may be used.
Restrictions on Placement
Functions of certain types are restricted on scope of usage. Functions whose names end in _lp
assume access to the log probability accumulator and are only available in the transformed parameter and model blocks. Functions whose names end in _rng
assume access to the random number generator and may only be used within the generated quantities block, transformed data block, and within user-defined functions ending in _rng
. See the section on function bodies for more information on these two special types of function.