Hi

I am having issues with my psi estimates being too high. I believe it to be an indexing issue in the “else” portion of my model. Any advice on what might be the issue or how to target the line of code that needs fixing is greatly appreciated!

Thank you

```
data {
int<lower=0> N; //of observations/ # temporal replication
int<lower=0> K; // of groups/ # of arrays
int pos[K]; // position of the first detection of each group
int y[N]; // observations/ Detection at each site for all temporal replication
int s[K]; // group size s={45,42,42,41,54,...}
int x[K]; // Observed occupancy at each site
vector[K] t_burn;
vector[N] air_temp;
}
parameters {
real a_psi;
real b1_psi;
real a_p;
real b1_p;
}
transformed parameters {
vector[K] logit_psi;
vector[N] logit_p;
logit_psi = a_psi + b1_psi * t_burn;
logit_p = a_p + b1_p * air_temp;
}
model {
// Priors
a_psi ~ normal(0, 1);
b1_psi ~ normal(0, 1);
a_p ~ normal(0, 1);
b1_p ~ normal(0, 1);
// Likelihood
for (i in 1:K) {
int t_d[s[i]];
t_d = segment(y, pos[i], s[i]);
for(j in 1:s[i]){
if (x[i] == 1) { // Occurred and observed
// print("psi before =", target());
1 ~ bernoulli_logit(logit_psi[i]);
// print("p before =", target());
t_d[j] ~ bernoulli_logit(logit_p[i]);
}
else {
// Occurred and not observed
target += log_sum_exp(bernoulli_logit_lpmf(1 | logit_psi[i])
+ bernoulli_logit_lpmf(0 | logit_p[i]),
// Not occurred
bernoulli_logit_lpmf(0 | logit_psi[i]));
// print("after target +=", target());
}
}
}
}
```