‘cito’: an R package for training neural networks using ‘torch’
View article (DOI) Preprint Software: cito
Abstract
Deep neural networks (DNN) have become a central method in ecology. To build and train DNNs in deep learning (DL) applications, most users rely on one of the major deep learning frameworks, in particular PyTorch or TensorFlow. Using these frameworks, however, requires substantial experience and time. Here, we present ‘cito', a user‐friendly R package for DL that allows specifying DNNs in the familiar formula syntax used by many R packages. To fit the models, ‘cito' takes advantage of the numerically optimized ‘torch' library, including the ability to switch between training models on the CPU or the graphics processing unit (GPU) which allows the efficient training of large DNNs. Moreover, ‘cito' includes many user‐friendly functions for model plotting and analysis, including explainable AI (xAI) metrics for effect sizes and variable importance. All xAI metrics as well as predictions can optionally be bootstrapped to generate confidence intervals, including p‐values. To showcase a typical analysis pipeline using ‘cito', with its built‐in xAI features, we built a species distribution model of the African elephant. We hope that by providing a user‐friendly R framework to specify, deploy and interpret DNNs, ‘cito' will make this interesting class of models more accessible to ecological data analysis. A stable version of ‘cito' can be installed from the comprehensive R archive network (CRAN).
What the paper shows and why it matters
(AI-generated)
Neural networks are increasingly used in ecology but usually built in Python-based frameworks such as PyTorch or TensorFlow, whose complexity, the paper notes, can be prohibitive for scientists with limited knowledge. R interfaces to these frameworks are easier, but they follow Python syntax rather than the formula notation of R packages like ‘lme4’ and leave plots, bootstrapping and explainable-AI (xAI) metrics to the user. R packages with formula notation, such as ‘nnet’ and ‘neuralnet’, lack modern deep-learning techniques and training on graphics processing units (GPUs). What was missing was an R package that fits modern neural networks as simply as any other R regression model and covers the whole analysis.
The paper presents ‘cito’, an R package that lets users specify, train and interpret a neural network in the model formula notation, in a single line of code. The package builds on ‘torch’ (PyTorch for R), so it needs no Python and can train on a GPU. It supports fully connected networks with modern training aids such as dropout and early stopping, and a baseline loss helps users spot networks that fail to converge. Predictions and xAI summaries can be bootstrapped to give confidence intervals, and p-values for the xAI summaries. In a feature comparison, the paper finds more functions in ‘cito’ than in ‘nnet’, ‘neuralnet’, ‘h2o’ and ‘brulee’; the paper calls ‘brulee’ very similar, also built on ‘torch’. In a runtime test on simulated data, GPU training time was practically independent of network size, and CPU training was on a par with ‘brulee’; for small networks ‘neuralnet’ was faster than both. A species distribution model of the African elephant illustrates the workflow.

The paper argues that ‘cito’ removes many hurdles for inexperienced users and saves programming time for experienced users who only want simple networks, because it fits into the R regression ecosystem. Only fully connected networks are supported, and the paper cautions that the bootstrap intervals and p-values are not guaranteed to cover the true value as often as stated or to keep their stated error rates, so they should be tested for each combination of data and settings. Loiseau et al. (2024) used ‘cito’ to train a neural network that they combined with random forests to infer the extinction risk of marine fish.
References
- Loiseau et al. (2024). Inferring the extinction risk of marine fish to inform global conservation priorities. PLOS Biology 22, e3002773. doi:10.1371/journal.pbio.3002773