I'm trying to figure out how to estimate a changepoint in my data, and to do so I would like to estimate random effects for the period prior to the changepoint and then for the period after the changepoint. However, I do not know when the changepoint should be, so I'm trying to estimate it. The problem I'm running into is that I am using the changepoint (cp) in my looping structure, and I am getting an error 'Cannot evaluate upper index of counter i'. I am guessing that I cannot loop using a variable I also want to estimate? I'm wondering if anyone has done this and/or has a suggestion on how to do this. Another potential problem is that I'm not using the counter index i in my commands, however, when I tried using a while loop I also ran into problems of the loop not breaking. Thank you in advance for any thoughts!
subset of the code:
cp ~ dunif(3,51)
for(i in 1:(cp-1)){
for(j in 1:nsite){
b[j] ~ dnorm(0,tau.site)
}
}
for(i in cp:nyear){
for(j in 1:nsite){
b1[j] ~ dnorm(0,tau.site1) # random site effects
}
}