Code and Stats

(NB: this page is very much a work in progress)

Here’s some R code I’ve written! The list begins at the start of my PhD (2015) and (hopefully) gets better from there. If you find any errors or if it’s untidy and you just wanna shout at me or find out more shoot me a message ( or @gfalbery on Twitter) or submit a pull request if it’s on GitHub and you’re motivated.

If you want to use some of the plotting and model summary functions I’ve made in the last few years, have a look at my conceitedly-named ggregplot package (includes general plots and functionality with MCMCglmm, INLA, and a few more things). Any other past and ongoing analyses can be found on my GitHub!

The main purpose of this page is to demonstrate how to code complex models, because this is what I found most difficult in the course of my PhD.


  • Spatial, social and genetic heritability models (Albery et al., in prep)


  • Spatial analysis (Albery et al., submitted)

    • The third chapter of my PhD focusses on spatial patterns in the wild population of red deer (Cervus elaphus).

    • How do you control for spatial autocorrelation to improve your models? How do you quantify variation in space?

    • Use a package called INLA! Models are simple and easy to fit (once you understand the model construction) and I’ve already written a tutorial for folks at Edinburgh:


  • Multi-response models (Albery et al., in review)

    • Allows you to examine the factors influencing multiple response variables while accounting for covariance between the two (and vice versa!)

    • Code here:

  • Zero-inflated models (Albery et al., 2018)

    • How do you deal with data with lots of zeroes?

    • What if different processes are generating the zeroes and the non-zeroes?

    • In my first chapter of my PhD I looked at modelling seasonal patterns of parasite counts in wild red deer.

    • We investigated seasonality, age-related changes in prevalence and intensity, and changes in seasonality between individuals.