Error report in easy bivariate normal distribution

It is just the bivariate normal distribution. But I got some error and I don’t know why :(

data {
  int<lower=0> N;
  matrix[N,2] X;
}

// The parameters accepted by the model. Our model
// accepts two parameters 'mu' and 'sigma'.
parameters {
  real mu[2];
  real<lower=0> sigma[2];
  real<lower=-1, upper=1> rho;
}

transformed parameters{
  matrix[2,2] S;
  S[1,1] = sigma[1]^2;
  S[2,2] = sigma[2]^2;
  S[1,2] = sigma[1]*sigma[2]*rho;
  S[2,1] = sigma[1]*sigma[2]*rho;
}

// The model to be estimated. We model the output
// 'y' to be normally distributed with mean 'mu'
// and standard deviation 'sigma'.
model {
  //y ~ normal(mu, sigma);
  mu[1] ~ normal(6.48,1);
  mu[2] ~ normal(1.43,1);
  sigma[1] ~ normal(1.85,1);
  sigma[2] ~ normal(0.4,1);
  rho ~ uniform(0,1);
  for(i in 1:N){
  X[i,] ~ multi_normal(mu,S);
  }
}

Error is like this:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:

row_vector ~ multi_normal(real[ ], matrix)

Available argument signatures for multi_normal:

vector ~ multi_normal(vector, matrix)
vector ~ multi_normal(vector[ ], matrix)
vector ~ multi_normal(row_vector, matrix)
vector ~ multi_normal(row_vector[ ], matrix)
vector[ ] ~ multi_normal(vector, matrix)
vector[ ] ~ multi_normal(vector[ ], matrix)
vector[ ] ~ multi_normal(row_vector, matrix)
vector[ ] ~ multi_normal(row_vector[ ], matrix)
row_vector ~ multi_normal(vector, matrix)
row_vector ~ multi_normal(vector[ ], matrix)
row_vector ~ multi_normal(row_vector, matrix)
row_vector ~ multi_normal(row_vector[ ], matrix)
row_vector[ ] ~ multi_normal(vector, matrix)
row_vector[ ] ~ multi_normal(vector[ ], matrix)
row_vector[ ] ~ multi_normal(row_vector, matrix)
row_vector[ ] ~ multi_normal(row_vector[ ], matrix)

Real return type required for probability function.
error in ‘model397588e61f4_Bivariate’ at line 45, column 29

43:   rho ~ uniform(0,1);
44:   for(i in 1:N){
45:   X[i,] ~ multi_normal(mu,S);
                                ^
46:   }

Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘Bivariate’ due to the above error.

Stan consider vectors and arrays different types. Multinormal distribution expect a vector so change the type of mu

parameters {
  vector[2] mu;
  real<lower=0> sigma[2];
  real<lower=-1, upper=1> rho;
}

You have declared rho with lower=-1 but its prior is uniform(0,1). Is the lower bound supposed to be 0 or -1? These need to be consistent.

Thanks!! But unfortunately, I got new error,

parameters {
  vector mu[2];
  real<lower=0> sigma[2];
  real<lower=0, upper=1> rho;
}

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in ‘model3975655decb_Bivariate’ at line 21, column 9

19: // accepts two parameters 'mu' and 'sigma'.
20: parameters {
21:   vector mu[2];
            ^
22:   real<lower=0> sigma[2];

PARSER EXPECTED:
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘Bivariate’ due to the above error.

Oh, I know why…

Thanks!!! That’s a very great help for me!!!

1 Like