update.packages("mgcv")
UKCEH-BioSS framework delivery workshop 2023
Welcome
This is the course website for the 2 day workshop delivered as part of the UKCEH-BioSS framework agreement. Some background was covered at this workshop.
The instructors for the course will be:
Schedule
Timings are indicative and we may bring components forward or backward according to participants needs (including ours).
Day 1
- Morning (09:30 - 12:00)
- Optional self-directed refresher on GAMs (see guidance below)
- Staff will be on call from 11:00 to 12:00 if you would like clarification about some of the pre-requisites (optional, send an email to thomas.cornulier@bioss.ac.uk if you would like to ask a question, and we’ll see you online shortly)
- Afternoon (13:00 - 17:00)
- Foreword: Thomas Cornulier / Pete Henrys
- Project 1: data fusion with change of support
- package, simulation, sampling (1hr Ana) PDF slides PowerPoint slides
- break (15 min)
- Data fusion modelling (1hr Fergus) HTML slides
- break (15 min)
- practical and vignette (1hr Ana and Fergus) (see vignette links at top of page)
- discussion (30 mins)
Day 2
- Morning (09:30 - 12:30)
- Project 2: estimating effect size variation across a zone of influence
- Introduction to the background and theory (1 hr Dave) HTML slides
- break (15 min)
- Application (10 min Thomas)
- Practical (30 min)
- Extensions (20 min Thomas)
- Practical (1 hr)
- Project 2: estimating effect size variation across a zone of influence
- Afternoon (13:30 - 17:00)
- Extended practical session, with one to one support available (2.5 hr, pick and mix across the two projects)
- Q&A with discussion of further applications (1 hr)
Pre-requisites
Theory
- Basic understanding of GAM theory
- 1D splines & spline bases
- (notion of penalization)
- 2D splines
- isotropic
- anisotropic
- Basic GAMs practice with
mgcv
in R- fitting the model
- interpreting the output
- making predictions
- model validation
See the resources section below, for useful materials.
Computing
We recommend updating to the latest version of R from r-project.org, then running:
to ensure that you have the latest version of mgcv
.
Exercises use a variety of R packages, the following should install the necessary packages:
install.packages(c("tidyverse", "patchwork", "gratia"))
For the project 1 practicals you’ll need the package ascot
written by Ana, Fergus and Jackie. You can install this using the remotes
package:
# if you don't have remotes installed
install.packages("remotes")
# install ascot
::install_git("https://gitlab.bioss.ac.uk/ukceh-bioss-framework/outputs/ascot.git") remotes
Or download the package and install manually (as a source package).
Data
The kittiwake data for use with the vignettes in project 2.
Running the Shiny app
Ana will talk through a Shiny app she’s written that is included as part of ascot
. You can run this on your own computer, once ascot
is installed using
::runApp(system.file(package="ascot", file="ASCOT_Shiny.R")) shiny
(This should pop-up a web browser with the app running.)
Self-directed GAM learning
Background knowledge assumption increases as you move down the list. Resources 1 and 2 cover all the key concepts you should need, in a condensed way (2D smoothing is only covered in resource 1). The rest is provided for reference.
Resources 3 and 4 are great and more comprehensive but require greater time investment (useful for browsing specific parts, or to come back to, as needed).
- Materials from our previous intro GAM workshop
- A condensed shortcut to 1D GAM theory with self-supporting text, in journal paper format: Gavin Simpson’s paper “Modelling palaeoecological time series using generalised additive models”.
- (3.5 h) GAM intro youtube video by Gavin Simpson
- (long) Online course on GAMs by Noam Ross
- Dave and co’s paper on modelling hierarchical effects using GAMs also has some potentially useful background information on GAMs. A useful reference if you would like you a headstart on material covered in the first afternoon, or for later reference / more technical detail.
- Dave’s preprint on Bayesian views of GAMs.
Further reading on GAMs
- Simon Wood’s book “Generalized Additive Models: An Introduction with R” has more information than you require on GAMs.
- Phil Bouchet’s package
dsmextra
which can be used to assess extrapolations with GAMs (focussed on count data, but the methods can be used in any setting). - Further resources on generalized additive models compiled by Noam Ross.
Things that came up during the course
- Getting from
mgcv
into other modelling frameworksmgcv
to JAGS/Nimble viajagam
paper (jagam
is part ofmgcv
)mgcv
into Stan using thebrms
package
- Smoothing categorical but ordered covariates in
mgcv
using a Markov random field a quick gist from Dave - Hierarchical GAMs background for project 1.
t2
manual page for constructing tensor products- If you have some spatial smooth where you need to carefully take into account the boundary (e.g., a coastline or an lake/loch with islands), you might want to use the soap film smoother.
- Wood, Bravington and Hedley (2008) is the original reference
- Again, Gavin Simpson’s blog has some useful information too.
- Dave and Benjamin Hlina have developed an R package to help setup these models. There is a vignette is available here to help.
- Thinking about links between the GAMs we’ve talked about in this course and things like kriging…
- Dave and co’s paper on equivalence between the INLA SPDE method and splines, which are a kind of Matern kriging.
- Code from that paper to use the model
This work is licensed under Attribution-NonCommercial-ShareAlike 4.0 International