Hi all,
I’m fitting a piecewise regression model with a random transition point, tp
.
I’m doing this based on data, x_data
, which is defined as a vector of length N
.
I’ve successfully used to below code to define a variable that tells me whether my data is before this transition point (region_1
) or after it, (region_2
):
parameters{
...
real tp; // transition point
...
}
transformed parameters {
// Introduce an indicator variable to distinguish between the 2 sides of the transition point
vector [N] region_2;
for (i in 1:N){
if (x_data[i] < tp) {
region_2[i] = 0;
} else {
region_2[i] = 1;
}
}
}
I wanted to develop this into a hierarchical model, with different model parameters (including tp
) for each different group. I need a version of my region_2
vector to work for this case.
My attempts to do this have so far not resulted in any samples. I believe there is a problem with how I am indexing my new region_2
parameter.
Please let me know if you have any experience or advice. Thanks!