20 Pedantic mode

Pedantic mode is a compilation option built into Stanc3 that warns you about potential issues in your Stan program.

For example, consider the following program.

data {
  int N;
  real x[N];
parameters {
  real sigma;
model {
  real mu;
  x ~ normal(mu, sigma);

When pedantic mode is turned on, the compiler will produce the following warnings.

  The parameter sigma has no priors.
Warning at 'ped-mode-ex1.stan', line 10, column 14 to column 16:
  The variable mu may not have been assigned a value before its use.
Warning at 'ped-mode-ex1.stan', line 10, column 18 to column 23:
  A normal distribution is given parameter sigma as a scale parameter
  (argument 2), but sigma was not constrained to be strictly positive.

Here are the kinds of issues that pedantic mode will find (which are described in more detail in following sections):

  • Distribution usages issues. Distribution arguments don’t match the distribution specification, or some specific distribution is used in an inadvisable way.
  • Unused parameter. A parameter is defined but doesn’t contribute to target.
  • Large or small constant in a distribution. Very large or very small constants are used as distribution arguments.
  • Control flow depends on a parameter. Branching control flow (like if/else) depends on a parameter value.
  • Parameter has multiple twiddles. A parameter is on the left-hand side of multiple twiddles.
  • Parameter has zero or multiple priors. A parameter has zero or more than one prior distribution.
  • Variable is used before assignment. A variable is used before being assigned a value.
  • Strict or nonsensical parameter bounds. A parameter is given questionable bounds.

Some important limitations of pedantic mode are listed at the end of this chapter.