This directory contains code from 'Hierarchical variation in phenotypic flexibility across timescales and associated survival selection shape the dynamics of partial seasonal migration' by Paul Acker, Francis Daunt, Sarah Wanless, Sarah J. Burthe, Mark A. Newell, Michael P. Harris, Carrie Gunn, Robert Swann, Ana Payo-Payo, and Jane M. Reid. If you are interested in developing collaborations using this field system or dataset then please get in touch with Jane M. Reid (jane.reid@abdn.ac.uk or jane.m.reid@ntnu.no) and Francis Daunt (frada@ceh.ac.uk). For questions about the analyses and/or the manuscript content, please contact Paul Acker (paul.acker@ntnu.no). ########################################################################### In our study, the capture-recapture data were analysed using a Bayesian statistical model coded in Stan language and run in R using package rstan. The model outputs, i.e. posterior samples of the model parameters, constitute the primary results our analyses. Further, we used these outputs to also calculate key derived parameters, in R. We then used the posterior samples of the model parameters and key derived parameters to calculate additional derived quantities which were helpful to present and summarise the results in various ways. The Stan code ('model_code.stan') is the model code for analysing the data (also provided in OSM S3 with colored text to ease reading). The R code ('main_analyses.R') is meant for reading the data into R, bundling data into the appropriate input format for the analysis with Stan, running the analysis of the Stan model, collecting the outputs and calculating key derived parameters, saving the posterior samples of the model parameters, calculating detailed numerical summaries for all model parameters and key derived quantities, and saving these numerical summaries. The R code ('derived_analyses.R') is meant for reading the posterior samples of the model parameters and key derived parameters, and using these posterior samples to calculate further derived quantities of interest for summarising and presenting the results provided in main text and OSM. Please see main text and Online Supporting Material for full details.