Could you please give me your sussing and corrections of this Stan code
When I check this code I received this error:
Error in stanc(filename, allow_undefined = TRUE) : 0
Semantic error in 'string', line 36, column 8 to column 46:
-------------------------------------------------
34: }
35: // Likelihood
36: y[n] ~ multi_normal_cholesky(mu, L_e);
^
37: }
38: }
-------------------------------------------------
Ill-typed arguments supplied to function 'multi_normal_cholesky':
(real, vector, matrix)
Available signatures:
(vector, array[] row_vector, matrix) => real
The first argument must be vector but got real
(vector, row_vector, matrix) => real
The first argument must be vector but got real
(vector, array[] vector, matrix) => real
The first argument must be vector but got real
(vector, vector, matrix) => real
The first argument must be vector but got real
(row_vector, array[] row_vector, matrix) => real
The first argument must be row_vector but got real
(Additional signatures omitted)
data {
int<lower=0> N; // Total number of valid observations
int<lower=0> K; // Number of predictors (tree-rings)
int<lower=0> M; // Number of unique streamflow stations
matrix[N, K] X; // Predictor matrix (only valid rows)
vector[N] y; // Flattened response vector (non-missing responses)
int<lower=1, upper=M> index[N]; // Index for streamflow stations (1 to M)
}
transformed data {
real<lower=0> df_e; // Degrees of freedom for the inverse Wishart distribution
df_e = M + 1; // Degrees of freedom for the inverse Wishart distribution
}
parameters {
vector[M] alphas; // Mean for each streamflow station
matrix[K, M] betas; // Coefficients for predictors, varying by station
cov_matrix[M] sigmas_e; // Covariance matrix for residuals
}
transformed parameters {
cholesky_factor_cov[M] L_e; // Cholesky factor of the covariance matrix
L_e = cholesky_decompose(sigmas_e); // Cholesky decomposition of the covariance matrix
}
model {
// Priors
alphas ~ normal(0, 100);
to_vector(betas) ~ normal(0, 100);
sigmas_e ~ inv_wishart(df_e, diag_matrix(rep_vector(1, M)));
// Likelihood
for (n in 1:N) {
vector[M] mu; // Initialize mean vector for the current observation
mu = alphas; // Start with alphas
// Compute the contribution from the predictors
for (m in 1:M) {
mu[m] += dot_product(X[n], betas[, m]); // Each entry of mu
}
// Likelihood
y[n] ~ multi_normal_cholesky(mu, L_e);
}
}
[edit: escaped code]