Programming resources for coding CJS models

Forum for discussion of general questions related to study design and/or analysis of existing data - software neutral.

Programming resources for coding CJS models

Postby brouwern » Thu Jan 23, 2014 1:46 pm

For heuristic purposes I would like to code my own basic CJS model from the ground up in R. I've only seen R and R2WingBugs code for Bayesian versions of the model. Catchpole (1995) "Matlab - an environment for analyzing ring-recovery and recapture data" has some helpful material. Can anyone recommend other resource for code (R, Matlab, Python) or pseudo code? Are there any papers, perhaps from the 1980s or 1990s, that discuss practical issues with regard to programming mark-recapture algorithms or software?

Thanks!

Nathan
Last edited by brouwern on Thu Jan 23, 2014 3:58 pm, edited 1 time in total.
brouwern
 
Posts: 9
Joined: Thu Jan 21, 2010 9:51 am
Location: USA

Re: Programming resources for writing

Postby cooch » Thu Jan 23, 2014 1:54 pm

brouwern wrote:For heuristic purposes I would like to code my own basic CJS model from the ground up in R. I've only seen R and R2WingBugs code for Bayesian versions of the model. Catchpole (1995) "Matlab - an environment for analyzing ring-recovery and recapture data" has some helpful material. Can anyone recommend other resource for code (R, Matlab, Python) or pseudo code? Are there any papers, perhaps from the 1980s or 1990s, that discuss practical issues with regard to programming mark-recapture algorithms or software?

Thanks!

Nathan


RMark already contains some routines that do CJS and JS models solely in R (see ?cjs and ?js). I'm not sure in anyone has done much work with them (anyone being the set exclusive of Jeff Laake).
cooch
 
Posts: 1628
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University

Re: Programming resources for writing

Postby jlaake » Thu Jan 23, 2014 2:32 pm

Actually those were removed from RMark awhile back and put into a package called marked that is on CRAN. All of my code is open access and available at https://github.com/jlaake.

The marked package now contains 2 implementations of the CJS model. The first is based on Shirley Pledger's hierarchical approach for handling 0 tail of the capture history. This is implemented in FORTRAN within the package but the R code is also shown in the help file for cjs.lnl (?cjs.lnl) except that it will not handle loss on captures. The FORTRAN code does handle loss on captures. That approach is also implemented in an ADMB TPL (c++ like) file and if you set use.admb=TRUE then it will use ADMB code. This allows fitting mixed effect models but this is in its infancy somewhat.

The second approach and what I consider to be the best approach uses hidden Markov models (HMM). The reason I think it is the best approach is because it easily extends to much more complicated models. I've not used it but from what I understand it is the basis of Esurge. See help ?HMMLikelihood and associated model-specific functions. Also, see http://www.afsc.noaa.gov/Publications/ProcRpt/PR2013-04.pdf which provides code for a purely R implementation of HMM. I use a FORTRAN version in marked because it is faster than pure R version. For a citation for marked software see http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12065/abstract.

Please, do not run off and start using marked over MARK! I recommend sticking with MARK and RMark (if it suits your needs) unless there is something in marked that isn't in MARK or you have models with lots of individual covariates and need to speed up the execution. I don't have the same infrastructure that MARK does, nor will you get the same level of documentation and help. I am adding new models for my open purposes that may also be useful for others at some point.

But you are certainly welcome to explore and use the code as you see fit. Just don't come to me if you modify the code and it no longer works. I recommend you focus your efforts on the HMM approach.

regards --jeff
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Programming resources for coding CJS models

Postby brouwern » Thu Jan 23, 2014 4:13 pm

Thank you for the details on what's under the hood of marked and the citation - very helpful. The marked package is a welcome addition to the tool box if for no other reason that is runs without any fuss on a Mac!

An ignorant question:
Are hidden-markov approaches to CJS models similar to state-space model approaches like those discussed in
Royle (2008) Modeling Individual Effects in the Cormack–Jolly–Seber Model: A State–Space Formulation.
Gimenez et al (2007) State-space modelling of data on marked individuals.

Or are HMM approaches a different type of approach? It seems like state-space approaches are usually Bayesian; and "state-space" occurs nowhere within your technical report.
brouwern
 
Posts: 9
Joined: Thu Jan 21, 2010 9:51 am
Location: USA

Re: Programming resources for coding CJS models

Postby jlaake » Thu Jan 23, 2014 4:33 pm

From what I understand, a version of mark.exe has been made available for the Mac. Thanks to Evan who gritted his teeth when he did so! :D

I was trained prior to wide use of Bayesian methods and even though I'm an author on a few papers that used a Bayesian approach that is not the way that I typically approach an analysis because of my training. I don't think state-space models are solely Bayesian. There are parallels with many different techniques that are devised. I've not read either paper you mentioned so I can't comment on the similarity.

I used a simple HMM to handle a problem in the late 1990s but never connected it then to capture-recapture. Now that I have, I find it a very useful way to approach for c-r analysis. My report was not intended to be all encompassing - solely to explain one way to approach c-r with HMM and why I think it is useful. Also, I found that many of the papers that used HMM approaches never explained how it worked. I thought it would be useful to demonstrate that starting with the CJS model and working up from there rather than the complicated models described in some of the original ms using HMM. It also provides one approach to the code you are interested in developing. As I explain in the report the reason I like HMM is that there is a single algorithm that works for any HMM model. Only the matrices need to change. There are likely parallels with what is in ESurge.

--jeff
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Programming resources for coding CJS models

Postby cooch » Wed Jan 29, 2014 4:13 pm

jlaake wrote:From what I understand, a version of mark.exe has been made available for the Mac. Thanks to Evan who gritted his teeth when he did so! :D


Nah -- it wasn't that bad. I just channeled my inner Steve Jobs (donned a faux black turtle-neck, John Lennon glasses, and and adopted the attitude that I -- Steve Jobs -- am the sole determinant of what you need, and therefore 'want', and by extension, are allowed to have, on one of 'my' computers), and went from there... ;-)

But, the Mac version of mark.exe does work (although I haven't tried to mke it play nice with RMark, which is the natural pairing, I suspect, for most), and is now as up-to-date as the Linux and Windows versions. In fact, I should have a 64-bit compilation for OS/X types by the end of the week, if not sooner (I simply found a student who had a newer Mac who graciously is willing to let me work with it long enough to get MARK compiled...).
cooch
 
Posts: 1628
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University


Return to analysis & design questions

Who is online

Users browsing this forum: No registered users and 19 guests