Hi all,
I am trying to analyze vector time series data in RStan. Assuming that a vector time series was taken at multiple sites, I intended to specify different covariance matrix for each site. This was done by embedding covariance matrices in an array with a dimension I (i.e., number of the sites) like:
parameters {
...
cov_matrix[N] Sigma[I];
...
}
model {
...
for (i in 1:I) {
for (t in 2:T) {
y[t, i] ~ multi_normal(mu_y_t, Sigma[i]);
...
}
where both y[t, i] and mu_y_t were specified as vectors of length N. When I run this model, however, I got the following error messages:
LOCATION: file=input; line=19, column=17
y[t, i] ~ multi_normal(mu_y_t, Sigma[i]);
^-- here
DIAGNOSTIC(S) FROM PARSER:
no matches for function name="multi_normal_log"
arg 0 type=vector
arg 1 type=vector
arg 2 type=row vector
unknown distribution=multi_normal
Parser expecting: "}"
which seems that here Sigma might be recognized in Stan as a matrix, rather than an array.
Was this a wrong approach to model multiple covariance matrices in Stan? Follwing is an R code which would reconstruct this error.
library(rstan)
model_code <- '
data {
int<lower = 0> T;
int<lower = 0> I;
int<lower = 0> N;
vector[N] y[T, I];
int<lower = 0> df;
cov_matrix[N] sm;
}
parameters {
cov_matrix[N] Sigma[I];
}
model {
for (t in 2:T) {
for (i in 1:I) {
vector[N] mu_y_t;
for (n in 1:N)
mu_y_t[n] <- y[n, t-1, i];
y[t, i] ~ multi_normal(mu_y_t, Sigma[i]);
}
}
for (i in 1:I)
Sigma[i] ~ wishart(df, sm);
}
'
T <- 20; I <- 10; N <- 3
y <- array(rnorm(T * I * N), dim = c(T, I, N))
data <- list(T = T, I = I, N = N, y = y,
df = N, sm = diag(N))
fit <- stan(model_code = model_code, data = data)
Regards,
Keiichi
----
Keiichi FUKAYA, Ph.D.
Faculty of Environmental Science
Hokkaido University