Hi,
I have the following Stan-code
data {
int<lower=1> N; // number of observations
int<lower=1> K; // dimension of observations
vector[K] y[N]; // observations:
vector[K] mu_x;
vector[K] mu_y;
}
parameters {
vector<lower=0>[K] sigma_x;
vector<lower=0>[K] sigma_y;
vector<lower=-1, upper=1>[K] rho;
}
model {
for k in (1:K) {
vector[2] mu = [mu_x[k], mu_y[k]]';
// cholesky decomposition of covariance matrix
matrix[2, 2] L_Sigma = [[sigma_x[k], 0], [rho[k] * sigma_y[k], sigma_y[k] * sqrt(1 - rho[k] * rho[k])]];
sigma_x[k] ~ normal(0, 20);
sigma_y[k] ~ normal(0, 20);
y[k] ~ multi_normal(mu[k], L_Sigma);
}
After running this, I get the posteriors of sigma_x, sigma_y and rho. When new data arrives I want to update the model. I believe the model is suited fort this because of the presence of the multivariate normal distribution. My question is how does the new update-Stan code looks? Do I read the three variables one-by-one as vectors in the data-section? Is the below code the correct way to go?
data {
int<lower=1> N; // number of observations
int<lower=1> K; // dimension of observations
vector[K] y[N]; // observations: a list of K vectors
vector[K] mu_x;
vector[K] mu_y;
vector[K] sigma_x;
vector[K] sigma_y;
vector[K] rho;
}
parameters {
vector<lower=0>[K] sigma_x;
vector<lower=0>[K] sigma_y;
vector<lower=-1, upper=1>[K] rho;
}
model {
for k in (1:K) {
vector[2] mu = [mu_x[k], mu_y[k]]';
// cholesky decomposition of covariance matrix
matrix[2, 2] L_Sigma = [[sigma_x[k], 0], [rho[k] * sigma_y[k], sigma_y[k] * sqrt(1 - rho[k] * rho[k])]];
sigma_x[k] ~ normal(0, 20);
sigma_y[k] ~ normal(0, 20);
y[k] ~ multi_normal(mu, L_Sigma);
}
Thanks in advance