User-defined normal distribution doesn't work



functions {
  // the _lpdf syntax has a special meaning (see below)
  real Bi_lpdf(vector x,vector mu, matrix S) {

    matrix[2,2] inv_s; 
    real xsx;
    // inverse_spd() provide The inverse of A where A is symmetric, positive definite.
    inv_s = inverse_spd(S); 
    // quad_from provides The quadratic form, i.e., B' * A * B.
    xsx = quad_form(inv_s, x - mu);
    return -(log_determinant(S) + xsx);
  }
}

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

// The parameters accepted by the model. 
parameters {
  vector[2] mu;
  real<lower=0> sigma[2];
  real<lower=0, 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. 
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,] ~ Bi(mu,S);
  }
}


This is a Bivariate normal distribution but I got some error report:

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

row_vector ~ Bi(vector, matrix)

Available argument signatures for Bi:

vector ~ Bi(vector, matrix)

Real return type required for probability function.
error in ‘model3977c57cb33_Bivariate_self’ at line 46, column 19

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

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

Try changing the signature from

  real Bi_lpdf(vector x,vector mu, matrix S) {

to

  real Bi_lpdf(row_vector x,vector mu, matrix S) {
2 Likes