I'm trying to sample from the posterior of this model: enter image description here
x is a 10x1 vector, mu is a 10x1 vector, sigma is a 10x10 matrix, psi_0 is a 10x10 matrix, 1 in bold is a 5x1 unity vector, and the rest are scalars. F and E are subscripts for the two group of stocks in our analysis (we're doing portfolio optimization). I try to run the following code:
stancode <- "data {
int<lower=1> T;
matrix[T,10] data_total;
real<lower=0> sigma_squared;
real k;
real<lower=0> r_squared;
matrix[10,10] psi;
}
parameters {
vector[10] mu_var;
matrix[10,10] Sigma_var;
real alpha_energy_var;
real alpha_fin_var;
real beta;
}
transformed parameters {
vector[10] mu_mean;
mu_mean = [alpha_fin_var,alpha_fin_var,alpha_fin_var,alpha_fin_var,alpha_fin_var,alpha_energy_var,alpha_energy_var,alpha_energy_var,alpha_energy_var,alpha_energy_var]';
}
model {
target += normal_lpdf(beta | k, sqrt(r_squared));
target += inv_wishart_lpdf(Sigma_var | 12, psi);
target += normal_lpdf(alpha_energy_var | beta, sqrt(sigma_squared));
target += normal_lpdf(alpha_fin_var | beta, sqrt(sigma_squared));
target += multi_normal_lupdf(mu_var | mu_mean, Sigma_var);
target += multi_normal_lupdf(data_total | mu_var,Sigma_var);
}"
stanmodel <- stan_model(model_code = stancode, model_name="stanmodel")
(data_total is the data matrix, and the "_var" suffixes are added just for consistency with the rest of the code)
The last line gives me an error: PARSER EXPECTED: "(", with respect to the penultimate line of the model code. I've seen on Stack that this kind of error happened to puzzle also more expert developers.
Can anyone help me? I don't really understand what went wrong.