stan-dev / pystan

PyStan, a Python interface to Stan, a platform for statistical modeling. Documentation: https://pystan.readthedocs.io
ISC License
342 stars 59 forks source link

"The parameter <parameter_name> has no priors” error reported in normal-inv-gamma model #347

Closed 9r0x closed 2 years ago

9r0x commented 2 years ago

Describe the bug

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

I’m seeing the following error despite having a prior defined for mu:

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

The code runs fine in pystan 2.19(with slight changes to how to build the model). I'm not sure if it's my code bug or issue with pystan. Thanks for the help!

Describe your system

Code to Reproduce


normal_inverse_gamma_data = {
    'y':
        np.array([
            3.54551763569501, 4.23799861761927, 4.72138425951628,
            -0.692265320368236, 3.04473513808788, 3.10721270732507,
            3.42982225852764, 3.12153903971176, 3.60532628639808])}

normal_inverse_gamma_data['n'] = len(normal_inverse_gamma_data['y'])

normal_inverse_gamma_code = """

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));
}

"""

normal_inverse_gamma_posterior = stan.build(normal_inverse_gamma_code,
                                            data=normal_inverse_gamma_data)
riddell-stan commented 2 years ago

Thanks for the report. I agree this looks like cause for concern.

Would you mind posting this on the Stan forum? You can tag it pystan and stanc3. (The warning you're seeing is from stanc3.) I'll respond to it there.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.