Warning: The parameter ... has 2 priors

I get the error “Warning: The parameter betaN has 2 priors” when using cmdstan or pystan3, from:


 parameters {   
   vector[NxN] betaN;
...
}

...

model {
...

betaN[1] ~ normal(0, 2);
for (i in 2:NxN) 
     betaN[i] ~ normal(0,1);
}

The message goes away if I loop over 1:NxN and remove the first prior line.
Should I ignore the warning? Is it a mistake?

Thanks!

Looks like a bug. What if you change to target+= normal_lpdf(betaN[i], 0, 1)?

It’s more that we know our crude warnings can produce false positives. Here it’s confused that betaN shows up on both sides of a sampling statement. But we don’t have enough power statically to tell that the loop is over different variables because that’s a technically undecidable problem because the range for i here can be anything.

If you don’t want to see the warning (even in pedantic mode), you can do

data {
   int<lower=2> N;
}

parameters {   
   real betaN_1;
   vector[N-1] betaN_trailing;
}

transformed parameters {
  vector[N] betaN = append_row(betaN_1, betaN_trailing);
}

model {
   betaN_1 ~ normal(0, 2);
   betaN_trailing ~ std_normal();
}
3 Likes

Nice refactoring, @jsocolar.

You could also define betaN as a local variable in the model block to save on I/O.