Hi everyone!
I am trying to do a capture-recapture model in nimble. Model works fine and all, however, I have population size covariate in the model and I thought it could also be calculated with the same model and used in the same model, could be useful to account for uncertainty in that variable.
But when I tried it out I got an error saying:
"The graph has cycles; topological sorting is only possible in acyclic graphs, Invalid value"
So, I was wondering if it is possible to use a derived parameter (population size) from latent state (z, true survival) in a model as a covariate in the same model in nimble?
The relevant code snippet is below (the model is rather big, if need be I can send it):
for (t in 1:(n.occasions-1)){
logit(phi_jpost[t]) <- alpha_phi + beta1*cov1[t] + beta2*cov2[t] + beta3t*popsize_out[t]
}
### LIKELIHOOD ##
for (i in 1:M){
## Define latent state at first occasion ##
z[i,1] <- 1 # Make sure that all M individuals are in state 1 at t=1
for (t in 2:n.occasions){
## State process: draw S(t) given S(t-1) ##
z[i,t] ~ dcat(ps[z[i,t-1], i, t-1, 1:6])}
# total jpost
z_jpost[i, t-1] <- equals(z[i,t], 2)
# total jpre
z_jpre[i, t-1] <- equals(z[i,t], 3)
# total apost
z_apost[i, t-1] <- equals(z[i,t], 4)
# total apre
z_apre[i, t-1] <- equals(z[i,t], 5)
} # i
} # t
for (t in 1:n.occasions){
N_jpost[t] <- sum(z_jpost[1:M,t])
N_jpre[t] <- sum(z_jpre[1:M,t])
N_apost[t] <- sum(z_apost[1:M,t])
N_apre[t] <- sum(z_apre[1:M,t])
popsize_out[t] <- N_jpost[t] + N_jpre[t] + N_apost[t] + N_apre[t]
}
Any help is appreciated.
Cheers,
Dilsad