The issue with the model is the use of "sigma" as opposed to
"sigma[j]". The integer parameter is not the source of the parsing
error. The correct model should be:
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real theta[J];
real mu;
real<lower=0> tau;
}
model {
theta ~ normal (mu, tau);
for (j in 1:J)
y[j] ~ student_t (4,theta[j], sigma[j]);
}
Daniel
On Thu, Aug 30, 2012 at 10:36 PM, Andrew Gelman
<
gel...@stat.columbia.edu> wrote:
> Here are 4 models. Two work, two don't.
>
> (1) This works:
>
> schools_code <- '
> data {
> int<lower=0> J; // number of schools
> real y[J]; // estimated treatment effects
> real<lower=0> sigma[J]; // s.e. of effect estimates
> }
> parameters {
> real theta[J];
> real mu;
> real<lower=0> tau;
> }
> model {
> theta ~ normal (mu, tau);
> for (j in 1:J)
> y[j] ~ normal (theta[j], sigma);
> }
> '
>
> (2) This works too:
>
> schools_code <- '
> data {
> int<lower=0> J; // number of schools
> real y[J]; // estimated treatment effects
> real<lower=0> sigma[J]; // s.e. of effect estimates
> }
> parameters {
> real theta[J];
> real mu;
> real<lower=0> tau;
> }
> model {
> for (j in 1:J){
> theta[j] ~ student_t (4, mu, tau);
> y[j] ~ normal (theta[j], sigma);
> }
> }
> '
>
>
> (3) This doesn't:
>
> schools_code <- '
> data {
> int<lower=0> J; // number of schools
> real y[J]; // estimated treatment effects
> real<lower=0> sigma[J]; // s.e. of effect estimates
> }
> parameters {
> real theta[J];
> real mu;
> real<lower=0> tau;
> }
> model {
> theta ~ normal (mu, tau);
> for (j in 1:J)
> y[j] ~ student_t(4,theta[j], sigma);
> }
> '
>
> It gives an error:
>
> TRANSLATING MODEL 'anon_model' FROM Stan CODE TO C++ CODE NOW.
> Error in stanc(file = file, model_code = model_code, model_name = model_name, :
> failed to parse Stan model 'anon_model' and error message provided as:
> LOCATION: file=input; line=15, column=7
>
> y[j] ~ student_t (4,theta[j], sigma);
> ^-- here
>
> DIAGNOSTIC(S) FROM PARSER:
>
> no matches for function name="student_t_log"
> arg 0 type=real
> arg 1 type=int
> arg 2 type=real
> arg 3 type=real[1]
> unknown distribution=student_t
> Parser expecting: <statement>
>
>
> (4) Aaahhh, so I thought it was a problem with the integer "4". But it also failed with the real "4.0":
>
> schools_code <- '
> data {
> int<lower=0> J; // number of schools
> real y[J]; // estimated treatment effects
> real<lower=0> sigma[J]; // s.e. of effect estimates
> }
> parameters {
> real theta[J];
> real mu;
> real<lower=0> tau;
> }
> model {
> theta ~ normal (mu, tau);
> for (j in 1:J)
> y[j] ~ student_t (4.0,theta[j], sigma);
> }
> '
>
> TRANSLATING MODEL 'anon_model' FROM Stan CODE TO C++ CODE NOW.
> Error in stanc(file = file, model_code = model_code, model_name = model_name, :
> failed to parse Stan model 'anon_model' and error message provided as:
> LOCATION: file=input; line=15, column=7
>
> y[j] ~ student_t (4.0,theta[j], sigma);
> ^-- here
>
> DIAGNOSTIC(S) FROM PARSER:
>
> no matches for function name="student_t_log"
> arg 0 type=real
> arg 1 type=real
> arg 2 type=real
> arg 3 type=real[1]
> unknown distribution=student_t
> Parser expecting: <statement>
>
>
> (Summary) The problem arises only with the model for y, not with theta.
> --
>
>