1

I am trying to do Variational inference, so that I can get the best approximating distribution with respect to the target distribution: a Normal-Inverse-Wishart.

Normal-Inverse-Wishart distribution

However when I compile the stan file with the model code it gives the error:

Error in stanc(file = file, model_code = model_code, model_name = ?>model_name, : 0 Syntax error in 'string', line 16, column 14 to column 15, parsing >error: Expected "generated quantities {" or end of file after end of model >block.

I have tried to investigate what this is referring to but I require some help. My R code is:

stan_file <- "RStan VI model.stan"
stan_model <- rstan::stan_model(file = stan_file) // Error occurs at this line

The RStan file model code is:

data {
  int<lower=1> N; // number of assets
  real<lower=0> nu0; // prior confidence for sigma
  matrix[N, N] sigma_0; // prior sigma
  real<lower=0> T0; // prior confidence for mu
  vector[N] mu0; // prior mu
}
parameters {
  matrix[N, N] sigma;
  vector[N] mu; 
}
transformed parameters {
  matrix[N, N] a;
  matrix[N, N] b;
  a = sigma0*nu0;
  b = sigma/T0;
}
model {
  target += inv_wishart_lpdf(sigma | nu0, a);
  target += normal_lpdf(mu | mu0, b);
}

I even tried changing the last section of the model code to:

model {
  sigma ~ inv_wishart(nu0, a);
  mu ~ normal(mu0, b);
}

But still same error. Would anyone know what the error is and how I can fix it?

Many thanks.

Best, Nihaar

Nihaar
  • 11
  • 2

0 Answers0