Preface

Why this book?

The hidden Markov modelling (HMM) framework has gained much attention in the ecological literature over the last decade, and has been suggested as a general modelling framework for the demography of plant and animal populations. HMMs are increasingly used to analyse capture-recapture data and estimate key population parameters (e.g., survival, dispersal, or recruitment) with applications in all fields of ecology (check out https://oliviergimenez.github.io/curated-list-of-HMM-CR-papers/). The first objective of this book is to illustrate the flexibility of HMM to decompose complex problems in smaller pieces that are easier to understand, model and analyse.

In parallel, Bayesian statistics is well established and fast expanding in ecology and related disciplines, as it resonates with the scientific reasoning and offers a natural framework for handling uncertainty. The popularity of Bayesian statistics also comes from the availability of free pieces of software (WinBUGS, OpenBUGS, JAGS, Stan) that allow practitioners to code their own analyses. The second objective of this book is to illustrate the use of the R package NIMBLE (de Valpine et al. 2017) to analyse capture-recapture data with HMM in a Bayesian framework. NIMBLE is seen by many as the future of Bayesian statistical ecology to deal with complex models.

An important part of the book consists in case studies from published papers presented in a tutorial style to abide by the “learning by doing” philosophy. The third objective of this book is to provide reproducible analyses with code and data to teach yourself by example.

Who should read this book?

This book is aimed at beginners who’re comfortable using R and write basic code, as well as connoisseurs of capture-recapture who’d like to tap into the power of the Bayesian side of statistics. For both audiences, thinking in the HMM framework will help you in confidently building models and make the most of your capture-recapture data.

What will you learn?

The book is divided into three parts. The first part Foundations is aimed at getting you up-to-speed with Bayesian statistics, NIMBLE, and hidden Markov models. The second part Transitions will teach you all about capture-recapture models for open populations, with reproducible R code to ease the learning process. The third part Case studies provides real-world case studies from the scientific literature that you can reproduce using material covered in previous chapters. These problems can either i) be used to cement and deepen your understanding of methods and models, ii) be adapted for your own purpose, or iii) serve as teaching projects. The data and code are available at https://github.com/oliviergimenez/banana-book/tree/master/appendix. The last chapter closes the book with take-home messages and recommendations.

What won’t you learn?

I won’t lie, there is some math in this book. But the equations I use are either simple enough to follow without a strong mathematical background, or they can be skipped without losing the thread. For those with a solid math background, you’ll find there isn’t much, and most of the derivations (e.g. posterior distributions) are tucked away in the code. I recognize that a certain level of abstraction can be useful, but my target audience is ecologists. I worried that leaning too heavily on formal math would feel like speaking a foreign language, and to be honest, I’m not even sure I could still ‘speak math’ as fluently as I once did.

I do not cover Bayesian statistics or even hidden Markov models exhaustively, I provide just what you need to work with capture-recapture data. If you are interested in knowing more about these topics, hopefully the section Suggested reading at the end of each chapter will put you in the right direction. There are also a number of important topics specific to capture-recapture that I do not cover, including closed-population capture-recapture models (Williams, Nichols, and Conroy 2002), spatial capture-recapture models (Royle et al. 2013), integrated population models (Besbeas and Morgan 2019), semi-Markov models (e.g. Choquet et al. 2011) and continuous-time models (Rushing 2023). These models can be treated as HMMs, but for now the usual formulation is just fine. These developments will be the subject of new chapters in a second edition, hopefully.

Prerequisites

This book uses primarily the R package NIMBLE, so you need to install at least R and NIMBLE. A bunch of other R packages are used. You can install them all at once by running:

install.packages(c(
  "bookdown", "coda", "forecast", "ggtern", "gtools", 
  "here", "janitor", "magick", "MCMCvis", "nimble", 
  "nimbleEcology", "patchwork", "pdftools", 
  "RColorBrewer", "sessioninfo", "tidyverse", 
  "wesanderson" 
))

Besides NIMBLE, I also make frequent use of the tidyverse packages in R and RStudio. For piping, I stick to %>% from the magrittr package. Since R 4.1.0, R has its own native pipe |>. Most of the code here should work with it too, although I have to admit, I haven’t really checked.

How this book was written

I wrote this book in RStudio http://www.rstudio.com/ide/ using bookdown http://bookdown.org/. The book website https://oliviergimenez.github.io/banana-book is hosted with GitHub Pages https://pages.github.com/, and automatically updated after every push by Github Actions https://github.com/features/actions. The source is available from GitHub https://github.com/oliviergimenez/banana-book.

The version of the book you’re reading was built with R version 4.5.0 (2025-04-11) and the following packages:

package version source
bookdown 0.43 CRAN (R 4.5.0)
coda 0.19-4.1 CRAN (R 4.5.0)
forecast 8.24.0 CRAN (R 4.5.0)
ggtern 3.5.0 CRAN (R 4.5.0)
gtools 3.9.5 CRAN (R 4.5.0)
here 1.0.1 CRAN (R 4.5.0)
janitor NA NA
magick 2.8.7 CRAN (R 4.5.0)
MCMCvis 0.16.3 CRAN (R 4.5.0)
nimble 1.3.0 CRAN (R 4.5.0)
nimbleEcology 0.5.0 CRAN (R 4.5.0)
patchwork 1.3.0 CRAN (R 4.5.0)
pdftools 3.5.0 CRAN (R 4.5.0)
RColorBrewer 1.1-3 CRAN (R 4.5.0)
sessioninfo 1.2.3 CRAN (R 4.5.0)
tidyverse 2.0.0 CRAN (R 4.5.0)
wesanderson 0.3.7 CRAN (R 4.5.0)

About the author

My name is Olivier Gimenez (https://oliviergimenez.github.io/). I am a senior (euphemism for not so young anymore) scientist at the National Centre for Scientific Research (CNRS; https://www.cnrs.fr/en) in the beautiful city of Montpellier, France.

I struggled studying maths, obtained a PhD in applied statistics a long time ago in a galaxy of wine and cheese. I was awarded my habilitation (https://en.wikipedia.org/wiki/Habilitation) in ecology and evolution so that I could stop pretending to understand what my colleagues were talking about. More recently I embarked in sociology studies because hey, why not.

Lost somewhere at the interface of animal ecology, statistical modeling and social sciences, my so-called expertise lies in population dynamics and species distribution modeling to address questions in ecology and conservation biology about the impact of human activities and the management of carnivores. I would be nothing without the students and colleagues who are kind enough to bear with me.

You may find me on BlueSky (https://bsky.app/profile/oaggimenez.bsky.social), LinkedIn (https://www.linkedin.com/in/olivier-gimenez-545451115/), GitHub (https://github.com/oliviergimenez), or get in touch by email at olivier|dot|gimenez|at|cefe|dot|cnrs|dot|fr.

Acknowledgements

Writing a book is quite an adventure, and a lot of people contributed to make this book a reality. I wish to thank:

  • Rob Calver, Sherry Thomas, Vaishali Singh and Kumar Shashi at Chapman and Hall/CRC.
  • Marc Kéry, Rachel McCrea, Byron Morgan and Etienne Prévost for their positive reviews of the book proposal I sent to Chapman and Hall/CRC, and their constructive comments and suggestions.
  • Marc Kéry for his precious pieces of advice on the process of writing.
  • Perry de Valpine, Daniel Turek, Chris Paciorek and Ben Goldstein for the NIMBLE and nimbleEcology R packages.
  • Colleagues who shared their data; See list at https://github.com/oliviergimenez/banana-book#readme
  • People who commented, corrected, offered pieces of advice; See list at https://github.com/oliviergimenez/banana-book#readme.
  • Yihui Xie for the bookdown R package.
  • Attendees of the workshops we run in relation to the content of this book (latest edition was in 2023, see https://oliviergimenez.github.io/bayesian-hmm-cr-workshop-valencia/)
  • Perry de Valpine, Sarah Cubaynes, Chloé Nater, Maud Quéroué and Daniel Turek for their help with running workshops in relation to the content of this book (2021 edition: https://oliviergimenez.github.io/bayesian-cr-workshop/; 2022 edition: https://oliviergimenez.github.io/hmm-cr-nimble-isec2022-workshop/).
  • Ruth King, Steve Brooks and Byron Morgan for the workshop on Bayesian statistics for ecologists we taught in Cambridge, the book we wrote together (King et al. 2009), and their contribution to statistical ecology.
  • Jean-Dominique Lebreton, Roger Pradel and Rémi Choquet for the workshops on modelling individual histories with state uncertainty we taught over the years, and sharing their science of capture-recapture with me.
  • My employer the Centre National de la Recherche Scientifique (CNRS) and folks at the Centre d’Écologie Fonctionnelle et Évolutive (CEFE): Being a researcher is a wonderful and meaningful profession, even though academia faces growing challenges with more competition, greater precarity, and fewer permanent positions. I am fortunate to work in a supportive environment at CNRS and CEFE, where people cultivate collaboration and a strong sense of community.
  • My family, including my mother, my parents-in-law for their kindness and hospitality, my amazing kids and wonderful wife for putting up with me while I was writing this book.