I'm trying to do a switchpoint analysis with STAN. I've got a data vector y
that has two different sequences of gaussian random variables. The goal is to find the posterior distribution of when a shift might have occured. I'm using RStan
to run it, but the error lies within STAN.
This is the STAN code;
data {
int N;
vector[N] y;
}
parameters {
real mu1;
real sigma1;
real mu2;
real sigma2;
real<lower=0, upper=N> shift;
}
model {
int i_shift <- round(shift);
for(n1 in 1:i_shift)
y[n1] ~ normal(mu1, sigma1);
for(n2 in i_shift:N)
y[n2] ~ normal(mu2, sigma2);
}
The parser (which comes with Rstudio) gives the following error;
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
ERROR at line 13
11: }
12: model {
13: int i_shift <- round(shift);
^
14: for(n1 in 1:i_shift)
PARSER EXPECTED: ";"
Error in stanc(model_code = paste(program, collapse = "\n"), model_name = model_cppname, :
failed to parse Stan model due to the above error.
Why can't it handle the variable assingment that does the casting? Does STAN require a different pattern for this sort of analysis. I've tried to create an integer variable in the parameters
but STAN doesn't appear to have support for random integer variables, only continous ones.