https://www.physalia-courses.org/
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. 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.
This course is aimed at higher degree research students and early career researchers working with time series data in the natural sciences (with particular emphasis on ecology) who want to extend their knowledge by learning how to add dynamic processes to model temporal autocorrelation. Participants should ideally have some knowledge of regression including linear models, generalized linear models and hierarchical (random) effects. But we’ll briefly recap these as we connect them to time series modelling.
Participants should be familiar with RStudio and have some fluency in programming R code. This includes an ability to import, manipulate (e.g. modify variables) and visualise data. There will be a mix of lectures and hands-on practical exercises throughout the course.
- Understand how dynamic GLMs and GAMs work to capture both nonlinear covariate effects and temporal dependence
- Be able to fit dynamic GLMs and GAMs in R using the {mvgam} and {brms} packages
- Understand how to critique, visualize and compare fitted dynamic models
- Know how to produce forecasts from dynamic models and evaluate their accuracies using probabilistic scoring rules
Please be sure to have at least version 4.1 — and preferably version 4.2 — of R
installed. Note that R
and RStudio
are two different things: it is not sufficient to just update RStudio
, you also need to update R
by installing new versions as they are released.
To download R
go to the CRAN Download page and follow the links to download R
for your operating system:
To check what version of R
you have installed, you can run
version
in R
and look at the version.string
entry (or the major
and minor
entries).
We will make use of several R
packages that you'll need to have installed. Prior to the start of the course, please run the following code to update your installed packages and then install the required packages:
# update any installed R packages
update.packages(ask = FALSE, checkBuilt = TRUE)
# packages to install
pkgs <- c("brms", "dplyr", "gratia", "ggplot2",
"marginaleffects", "tidybayes", "zoo",
"viridis", "remotes")
# install those packages by setting Ncpus to number of CPU cores you have available
install.packages(pkgs, Ncpus = 4)
For both mvgam
and brms
, it is highly recommended that you use the Cmdstan
backend, with the cmdstanr
interface, rather than using rstan
. To install Cmdstan
and the relevant interface, first install cmdstanr
using the following:
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
And then follow instructions provided by the Stan
development team here to ensure the backend is installed and the toolchain is setup properly
Finally, we will make use of the development version of the mvgam
package as it is not quite ready for CRAN. You can install this package using the following:
# Download and install mvgam
remotes::install_github('nicholasjclark/mvgam', force = TRUE)
09:00 - 12:00 (Berlin time): live lectures and introduction to / review of the practicals
3 additional hours: self-guided practicals using annotated R scripts
Lecture 1 (html | pdf)
Lecture 2 (html | pdf)
Tutorial 1 (html)
- Introduction to time series and time series visualization
- Some traditional time series models and their assumptions
- GLMs and GAMs for ecological modelling
- Temporal random effects and temporal residual correlation structures
Lecture 3 (html | pdf)
Tutorial 2 (html)
- Dynamic GLMs and Dynamic GAMs
- Autoregressive dynamic processes
- Gaussian Processes
- Dynamic coefficient models
Lecture 4 (html | pdf)
Tutorial 3 (html)
- Bayesian posterior predictive checks
- Forecasting from dynamic models
- Point-based forecast evaluation
- Probabilistic forecast evaluation
Lecture 5 (html | pdf)
Tutorial 4 (html)
- Multivariate ecological time series
- Vector autoregressive processes
- Dynamic factor models
- Multivariate forecast evaluation
- Extended practical examples using
mvgam
- Review and open discussion