Dear Forum,

I have been using Cormack Jolly Seber (CJS) examples in the manual and online to try and estimate posteriors for survivability and prob of recapture, in addition to the influence of a trait which reducing survivability (phi).

p = prob of recapture

phi = prob of survivability

dphi[4] = reduction in survivability based one 4 levels (1=nil, 2=low, 3=med, 4=high)

I created a dataset and for normal p and phi estimations it works using the code in the manual.

Sample of capture recapture data (X)

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23

[1,] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0

[2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

[3,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0

[4,] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

[5,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0

[6,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0

The additional parameter is also included in the generated data as Y. Most animals do NOT exhibit this, but it is present.

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22

[1,] 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1

[2,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

[3,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3

[4,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

[5,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1

[6,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

I am getting initialization errors, but have tried to truncate priors to mitigate that as an initial work-around.

Any pearls of wisdom would be greatly appreciated.

Thanks,

Steve

```
data {
int<lower=1> K; // capture events
int<lower=0> I; // number of individuals
int<lower=0,upper=1> X[I,K]; // X[i,k]: individual i captured at k (binary matrix)
int<lower=1,upper=4> Y[I,K-1]; // Y[i,k-1]: individual influence on future survivability (1=nil, 2=low, 3=med, 4=high)
}
transformed data {
int<lower=0,upper=K+1> first[I]; // first[i]: ind i first capture
int<lower=0,upper=K+1> last[I]; // last[i]: ind i last capture
first = rep_array(K+1,I);
last = rep_array(0,I);
for (i in 1:I) {
for (k in 1:K) {
if (X[i,k] == 1) {
if (k < first[i])
first[i] = k;
if (k > last[i])
last[i] = k;
}
}
}
}
parameters {
vector<lower=0,upper=1>[K-1] phi; // phi[k]: Pr[alive at k + 1 | alive at k]
vector<lower=0,upper=1>[K] p; // p[k]: Pr[capture at k]
real<lower=0,upper=1> dphi[4]; //upper limit should be < phi... but we I set it as 1?
}
model {
for (i in 1:I) {
if (last[i] > 0) { //implies there are some captures for the animal atleast (put in based on released animals never originally caught)
for (k in (first[i]+1):last[i]) {
//SURVIVABILITY
if (Y[i, k-1] > 1) // if individual influencing parameter exists
target += (log(phi[k-1] - dphi[Y[i,k-1]])); // uses one case, else uses another
else
target += (log(phi[k-1]));
//CAPTUREABILITY
if (X[i,k] == 1)
target += (log(p[k])); // i captured at k // increment_log_prob(log(p[k]));
else
target += (log1m(p[k])); // i not captured at k // increment_log_prob(log1m(p[k]));
}
}
}
p ~ normal( 0.3 , 0.2 );
phi ~ normal( 0.7 , 0.1 );
dphi[1] ~ uniform( 0.4 , 0.6 ); //This is coded to be redundant above
dphi[2] ~ normal( 0.3 , 0.1 ); // T[0,(min(phi)-0.01)];
dphi[3] ~ normal( 0.6 , 0.1 ); // T[0,(min(phi)-0.01)];
dphi[4] ~ normal( 0.9 , 0.2 ); // T[0,(min(phi)-0.01)];
}
```