stan-dev / example-models

Example models for Stan
http://mc-stan.org/
771 stars 479 forks source link

CJS models with STAN: example-models/misc/ecology/mark-recapture/cjs-K.stan #119

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, I'm trying to implement the stan code for CJS models explained in the example above (title). But I have some doubts about the parameters estimated and the code itself. In my case, all the individuals are marked as chicks, it means, I know the exact age in each time t. When you run the model and get the parameters, you obtain p[1], but, as I have chicks, I know for sure that p[1] is always 1, because it is the ringing time. Besides, I don't understand why do we estimate p[1] because the recapture probability begins in t+1, and then, we only will have (in my case with 11 encounter occasions), 10 phi's and 10 p's, but we obtain 11 p. And I don't understand why.

In the other hand, I also don't understand why we put in the code:

transformed data { int first[I]; // first[i]: ind i first capture int last[I]; // last[i]: ind i last capture

Because, the last ringing year (K) don't compute for the calculation of the probabilities of interest, and then I guess the first capture should be from 1 to K-1, and the last only until K.

And the last question is also related with the block of transformed parameters:

first <- rep_array(K+1,I); last <- rep_array(0,I);

Here, I don't understand the meaning of K+1 again, and the zeros for the last recapture. Just for concluding, I have also problems with NAs in the capture-recapture matrix with STAN. They are marking when the individual IS NOT in the study, but it doesn't work with STAN as I have the code (the same of the example).

I'm beginning with STAN and maybe some questions are trivial, I would appreciate some help.

bob-carpenter commented 7 years ago

Welcome to Stan. I'm sorry that the first thing I'm going to have to tell you is that you're in the wrong place for help on modeling. We have a discussion board here:

http://discourse.mc-stan.org

and the rest of mc-stan.org has instructions on submitting bugs or feature requests through issues like this.

To answer your top-level question, there's a description of these models in the manual. Stan's simply implementing the log density and there are examples of this also in the literature for CJS for fitting maximum likelihood estimates (you need the same marginalization over discrete parameters). There have been many many examples posted and published on these mailing lists. Also, the entire Kery and Schaub book has been translated to Stan as part of this repo. And Fraenzi Korner-Nievergelt wrote a book that has examples on coding CJS with covariates in Stan.