How to understand error "The parameter <parameter_name> has no priors" in Pystan 3.x?

Hi, I’m learning to do a Bayesian inference with normal-inverse-gamma conjugate prior.

data {  
    int<lower=1> n; 
    array[n] real y;
}

parameters {
    real mu;
    real<lower=0> sigma2;
}

model {
    real mu0 = 0;
    real lambda = 0.054;
    real alpha = 1.12;
    real beta = 0.4;

    sigma2 ~ inv_gamma(alpha, beta);
    mu ~ normal(mu0, sqrt(sigma2) / sqrt(lambda));
    y ~ normal(mu, sqrt(sigma2));
}

I’m seeing the following error but not sure why my statement is not a prior:

Building: found in cache, done.
Messages from stanc:
Warning: The parameter mu has no priors.

I’m using Python 3.9.10 and pystan 3.4.0, and the code works fine with 2.x pystan.

Also, if I replace sqrt(sigma2) with a number such as 2, it would run without issue. Is there something wrong with my code?

Weird. You definitely have a prior structure there, so seems like a parsing failure. I suggest you use cmdstanpy rather than PyStan as cmdstanpy will have the most up-to-date version of Stan & it’s parsing tools.

Edit: oh, I see now that you’re using PyStan 3.4, which is indeed using the newest Stan (2.29). Hm. Maybe try with cmdstanpy anyway and report back?

It is not error but warning from stanc3 pedantic mode

See section on priors

1 Like

Pedantic mode is experimental and known to produce false positive warnings. See for example

3 Likes

I asked @Shukai_Ni to post this here.

The source of the message is indeed pedantic mode, which PyStan turns on by default.

I still think turning on pedantic mode is a good idea. Pedantic mode plays to Stan’s strengths. It’s precisely the sort of thing you’d expect to see in Stan and not in, for instance, PyTorch or Tensorflow Probability.

That said, the warning is confusing. Could it be made more verbose or reduced to an “Info:” message? How about “Note: The parameter mu has not been given a prior distribution.”