# Fitting HMM/multievent capture-recapture models with TMB

Following my attempts to fit a HMM model to [capture-recapture data with Rcpp](http://localhost:1313/post/multievent_in_rcpp/) and to [occupancy data with ADMB](http://localhost:1313/post/occupancy_in_admb/), a few colleagues suggested TMB as a potential alternative for several reasons (fast, allows for parallel computations, works with R, accomodates spatial stuff, easy implementation of random effects, and probably other reasons that I don't know).

I found materials on the internet to teach myself TMB, at least what I needed to implement a simple HMM model. See here for a linear regression and a Gompertz state space model examples, here for the same linear regression example on Youtube (that’s awesome!) and many other examples here. However, I got stuck and posted my desperate request for help on the TMB forum. Guess what, I got an answer less than a few hours after - thank you Mollie Brooks!

The R code is available on my GitHub here. Minimizing the deviance coded with TMB was… wait for it… > 300 times faster than using the deviance coded in standard R.

Hope this is useful.