Rstats

Ecological forecasting with R 📦’s {mvgam} and {brms}

Time series analysis and forecasting are standard goals in applied ecology. But most time series courses focus only on traditional forecasting models such as ARIMA or Exponential Smoothing. These models cannot handle features that dominate ecological data, including overdispersion, clustering, missingness, discreteness and nonlinear effects. Using the flexible and powerful Bayesian modelling software Stan, we can now meet this complexity head on. R packages such as {mvgam} and {brms} can build Stan code to specify ecologically appropriate models that include nonlinear effects, random effects and dynamic processes, all with simple interfaces that are familiar to most R users. In this course you will learn how to wrangle, visualize and explore ecological time series. You will also learn to use the {mvgam} and {brms} packages to analyse a diversity of ecological time series to gain useful insights and produce accurate forecasts. All course materials (presentations, practical exercises, data files, and commented R scripts) will be provided electronically to participants.

2025 R Workshops @ UQ

I have recently joined the R Workshops @ UQ team, which has been conducting several R Workshops at the University of Queensland each year since 2012. The team is composed of a wonderful group of quantitative ecologists who have learnt data analysis and data science through application to real-world problems in R. Because we are self-taught, we want to help others avoid some of the mistakes we made when we were setting out to learn and use R. We have now taught >1,500 students at these workshops, and we look forward to helping the next generation of R programmers and applied statisticians learn the skills they need to meet the demands of the modern research environment. The 2025 workshops, happening over 5 days in February, will cover the tidyverse, ggplot2, linear models, Generalized Linear Models, Generalized Additive Models, spatial and spatiotemporal modelling, multivariate modelling and much more!

State-Space Vector Autoregressions in mvgam

Vector Autoregressions (VAR models), also known as Multivariate Autoregressions (MAR models), offer a way to model delayed and contemporaneous interactions among sets of multiple time series. These models are widely used in econometrics and psychology, among other fields, where they can be analyzed to ask many interesting questions about potential causality or stability. But software to fit these models to real-world time series, which often present as non-Gaussian counts, proportions or even binary observations with measurement error, is lacking. Here I show how to fit VARs in a State-Space format, and how to interrogate the models to ask meaningful questions about interactions and stability, using the mvgam package in R.

Incorporating time-varying seasonality in forecast models

Many time series show repeated seasonal patterns, and fitting models that can capture this seasonality is a major focus of time series forecasting algorithms. There are a lot of useful, established methods to deal with this (i.e. SARIMA, Harmonic regression), but sometimes the seasonal patterns change over time. Fewer time series and forecasting models can handle this feature. This post introduces some strategies for capturing time-varying seasonality and time-varying periodicity in Dynamic Generalized Additive Models, using the mvgam package in R.

Ecological forecasting with R 📦’s {mvgam} and {brms}

Time series analysis and forecasting are standard goals in applied ecology. But most time series courses focus only on traditional forecasting models such as ARIMA or Exponential Smoothing. These models cannot handle features that dominate ecological data, including overdispersion, clustering, missingness, discreteness and nonlinear effects. Using the flexible and powerful Bayesian modelling software Stan, we can now meet this complexity head on. R packages such as {mvgam} and {brms} can build Stan code to specify ecologically appropriate models that include nonlinear effects, random effects and dynamic processes, all with simple interfaces that are familiar to most R users. In this course you will learn how to wrangle, visualize and explore ecological time series. You will also learn to use the {mvgam} and {brms} packages to analyse a diversity of ecological time series to gain useful insights and produce accurate forecasts. All course materials (presentations, practical exercises, data files, and commented R scripts) will be provided electronically to participants.

First release of mvgam(v1.1.0) to CRAN

The mvgam package has been officially released to CRAN. This package fits Bayesian Dynamic Generalized Additive Models to sets of time series. Users can build dynamic nonlinear State-Space models that can incorporate semiparametric effects in observation and process components, using a wide range of observation families. Estimation is performed using Markov Chain Monte Carlo with Hamiltonian Monte Carlo in the software Stan.

How to interpret and report nonlinear effects from Generalized Additive Models

Generalized additive models (GAMs) are incredibly flexible tools that fit penalized regression splines to data. But interpreting nonlinear effects from GAMs is not as easy as interpreting linear models. In this post I provide 3 simple steps to help you understand and interpret nonlinear effects from GAMs using the mgcv R package.

Phylogenetic smoothing using mgcv

Use species’ phylogenetic or functional relationships to inform and partially pool hierarchical, nonlinear smooth functions in Generalized Additive Models with mgcv

Temporal autocorrelation in GAMs and the mvgam package

Temporal autocorrelation is a dominant feature of time series. We often want to use Generalized Additive Models (GAMs) to fit smoothing splines to time series data, but incorporating autocorrelation in these models can be difficult. Enter the mvgam package

Rapid winter warming associated with major shifts in coastal fish communities

Marine ecosystems are under increasing threat from warming waters. Winter warming is occurring at a faster rate than summer warming for ecosystems around the world, but most studies focus on the summer. Here, we show that winter warming could affect coastal fish community compositions in the Mediterranean Sea using a model that captures how biotic associations change with sea surface temperature to influence species’ distributions for 215 fish species. Species’ associations control how communities are formed, but the effect of winter warming on associations will be on average four times greater than that of summer warming. Projections using future climate scenarios show that 60% of coastal Mediterranean grid cells are expected to lose fish species by 2040. Heavily fished areas in the west will experience diversity losses that exacerbate regime shifts linked to overexploitation. Incorporating seasonal differences will therefore be critical for developing effective coastal fishery and marine ecosystem management. Clark, N.J., Kerry, J.T. & Fraser, C.I. Rapid winter warming could disrupt coastal marine fish community structure. Nature Climate Change 10, 862–867 (2020). https://doi.org/10.1038/s41558-020-0838-5