Each series k is drawn from its own mixture component
according to theta. The draw of mixture component is
marginalized out. I used the notation from the paper.
- Bob
/**
* AR(1) version
*/
data {
int<lower=0> K; // # series
int<lower=0> T; // # observations / series
int<lower=1> H; // # clusters
matrix[K, T] z; // observations
}
parameters {
vector[H] phi0; // AR(1) coefficients
vector[H] phi1;
vector<lower=0>[H] sigma; // innovations scales
simplex[H] theta; // mixture proportions
}
model {
vector[H] lp;
vector[H] log_theta;
log_theta <- log(theta);
for (k in 1:K) {
lp <- log_theta;
for (h in 1:H)
for (t in 2:T)
lp[h] <- lp[h] + normal_log(z[k, t], phi0[h] + phi1[h] * z[k, t-1],
sigma);
increment_log_prob(lp);
}
}
You can make it more efficient by replacing the inner loop over T
with:
lp[h] <- lp[h]
+ normal_log(z[k, 2:T], phi0[h] + phi1[h] * z[K, 1:(T-1)]);
There's no model for z[k, 1] here. But you could add one if you
wanted.
I'd also recommend adding at least weakly informative priors.
- Bob
> On May 30, 2016, at 9:00 AM, Bin Han <
danie...@gmail.com> wrote:
>
> sorry.. here it is.
> <tscluster.pdf>
>
>> On May 30, 2016, at 8:54 AM, Bin Han <
danie...@gmail.com> wrote:
>>
>> Sorry.. here it is
>> <Multivariate_Time_Series_Analysis_nodrm.pdf>