DI Models

Blog post: Developing the DImodels R Package – the technical and personal story!

November 2023

By Rafael Moral, Associate Professor in Statistics at Maynooth University


The DImodels R package was first published in October 2020. The package is for modelling data from biodiversity and ecosystem function studies, and it implements the Diversity-Interactions modelling approach. These models can jointly model the effects of richness, composition and evenness on ecosystem function.

The DI function in the package is for fitting Diversity-Interactions models one at a time, and it can estimate Diversity-Interaction models for univariate data using different types of Interactions components. It allows for estimating the nonlinear parameter θ for the average pairwise (when all species interactions are considered equal), functional groups (when interactions are dictated by functional group membership), additive species (when there are species-specific contributions to the interactions), and full pairwise (when all interactions are unique) models and comes with flexibility for users to tailor the model according to their data or study setup. But that was not the most difficult implementation we did in the package.

Besides defining a streamlined framework for model fitting, by far, the most challenging function to implement was the autoDI function, which provides a walkthrough of fitting and comparing several Diversity-Interactions models. Currently, its pipeline is as represented by this figure:


autoDI pipeline

But it wasn’t always like this. Let me take you on a quick tour of the history of the development of the package!

Caroline Brophy and I started developing the package back in the Summer of 2018, while she was still at Maynooth University and we would have weekly meetings aiming to have the package ready by the Summer of 2019. John Connolly (Professor Emeritus, University College Dublin) would also come over to Maynooth from time to time, and the DImodels package began to take shape. However, it was our goal that the package allowed for extensions to be built using its functionalities, and that it established a streamlined DI modelling analytical framework… so we needed more time to ensure our implementation was fulfilling these criteria!

In December 2019, Caroline moved to Trinity College Dublin and we continued with remote meetings that lasted throughout the lockdowns of 2020. After extensive testing cycles (represented very accurately in the diagram below) we finally reached a first “publishable” version of the package.


autoDI pipeline

The first implementations of autoDI considered only a small number of tests and potential models, and the function was significantly changed multiple times before reaching its final current state. In fact, the findings in Vishwakarma et al. (Estimation of the non-linear parameter in Generalised Diversity-Interactions models is unaffected by change in strcuture of the interaction terms, Environmental and Ecological Statistics, 2023) guided a complete revamping of the autoDI function. Luckily, when it came to reimplementing and re-modularising autoDI, Rishabh Vishwakarma (PhD student at Trinity College Dublin) became deeply involved; I recall one particularly intense full day of coding side-by-side with Rishabh when the new (current) version of autoDI really took shape.

To crown our efforts, a paper on the current version (1.2) has been recently published by Methods in Ecology and Evolution, titled Going beyond richness: Modelling the BEF relationship using species identity, evenness, richness and species interactions via the DImodels R package. When I started working on this project five years ago, I never imagined the directions it would end up taking. I am looking forward to finding out where it will be five years from now!