The Tidy Ecology course

A numbered course in ecological data analysis with R: field data, diversity, ordination, GLMs, mixed models, spatial layers, and checking the result holds.

The start-here page is a map of the whole site, grouped by subject, and it assumes you already know which subject you want. This page assumes the opposite. It is one route, numbered, from a messy field sheet to a result you would be willing to defend, and it says what each step is for and why it comes where it does.

Forty-four tutorials, in order. That is a term of evening reading rather than a weekend, and skipping ahead is fine as long as you come back: the later parts lean on the earlier ones, and the two places where that dependency really bites are called out below. Everything runs in base R with a small number of well established packages, on data small enough to sit in memory.

Part one: get the data into R

Most of the time an ecologist loses to R is lost here, before any method is chosen. These six steps are the ones that stop a spreadsheet from arriving in R as something subtly other than what it says on the field card.

  1. Setting up R and RStudio for ecology puts a project in place instead of a working directory, and shows the hidden-state bug that changes an answer with nothing on screen to say so.
  2. Reading field data into R covers the arguments that decide whether an empty cell becomes a zero, a missing value, or a character column.
  3. Wide and long: reshaping species data moves between the species matrix every community method wants and the one-row-per-record shape every database gives you.
  4. Cleaning species names before you count builds a lookup table, and makes the case against fuzzy matching by showing what it merges.
  5. Dates and times in ecological data is short and saves entire field seasons: the transposed day and month that never warns, and where the silent missing value comes from.
  6. Joining ecological tables without losing zeros is the step that decides whether your absences survive, which decides most of what follows.

Part two: a first result, and what it is worth

Before any modelling, produce something and put an interval on it. A number without an interval is not yet a result.

  1. Your first ggplot: data, aes and geom covers the three pieces of a plot and the mapping-versus-setting mistake everyone makes once.
  2. Summarising ecological data by group groups and summarises, and explains why the mean of proportions is not the pooled proportion.
  3. From a field sheet to your first analysis runs parts one and two end to end on a messy sheet.
  4. Standard errors and confidence intervals is what a standard error actually measures, and why coverage is the property that matters.

Part three: describe the community

Community data have their own summaries, and the choice between them is a choice about what you are claiming, not a matter of taste.

  1. Diversity indices in R gets richness, Shannon and Simpson out of a site-by-species matrix.
  2. When not to use Shannon is the reason step eleven is not the end of the story, and introduces Hill numbers.
  3. Rarefaction and accumulation curves compares richness across uneven effort, which is the usual situation.
  4. Estimating species richness beyond your sample goes after the species you did not see, and is honest about these estimators being lower bounds.
  5. Beta diversity partitioning splits the difference between two sites into turnover and nestedness, which answer different ecological questions.

Part four: find the structure

Ordination is where community data become a picture. The picture is only as good as the distance underneath it, which is why the first step here is the distance and not the method.

  1. Choosing a dissimilarity index is the decision every ordination and PERMANOVA inherits from you.
  2. NMDS ordination is the workhorse for composition, with stress read properly.
  3. PCA on environmental data is the abiotic counterpart, and the standardisation question that goes with it.
  4. envfit and PERMANOVA tests whether the groups on the picture differ, rather than asserting it from the picture.
  5. Common PERMANOVA mistakes is the one to read before you report a result, not after: dispersion against location, permutation structure, and unbalanced designs.

Part five: model a response

This is the first place where skipping ahead hurts. Everything after this part assumes you can fit a GLM, read its residuals and predict from it on the scale you care about.

  1. Classical tests as linear models collapses the t-test and ANOVA into the one framework that the rest of the course extends.
  2. Logistic regression for presence-absence is the binomial case, with the logit link made concrete.
  3. GLMs for count data explains why counts are not logged and what to fit instead.
  4. Offsets for rates and densities is how effort enters a count model, and it is not a covariate.
  5. GLM residual diagnostics covers why the familiar residual plot misleads on a GLM, and what to look at in its place.
  6. Predicting on the response scale builds the interval on the link scale first, which is the order that keeps it inside the possible range.
  7. Collinearity and VIF is the diagnostic for predictors that carry the same information twice.

Part six: the structure regression ignores

Field data are grouped, nested and repeated, and a model that pretends otherwise reports intervals that are too narrow rather than too wide.

  1. Pseudoreplication in ecology is the concept, with the error rate it costs measured.
  2. GLMMs for nested counts is the fix, with random intercepts.
  3. Random slopes in mixed models covers when a shared slope understates the uncertainty on the effect you are reporting.
  4. GAM species response curves relaxes the straight line where the ecology says the response is humped.
  5. Model selection and AIC is what AIC measures, and what it does not.

Part seven: put it on a map

Enough spatial work to handle occurrence records and raster layers, and to notice when nearby sites are quietly repeating each other.

  1. Cleaning GBIF and iNaturalist records comes before any mapping, because bad coordinates map perfectly well.
  2. Richness mapping with sf is vector data, projections and a map that means something.
  3. Raster basics with terra covers raster structure and map algebra.
  4. Spatial autocorrelation and Moran’s I tests whether your residuals are independent in space, which parts five and six assumed without checking.

Part eight: make the result hold up

The second place where skipping hurts. A result that nobody can reproduce, and whose data nobody compared with the design, is not finished, however good the model is.

  1. Bootstrap confidence intervals gives you an interval where no formula exists, which by this point is most of what you will want.
  2. Power analysis by simulation answers the design question with the model you actually intend to fit.
  3. Checking your data against the design is the step almost every course leaves out: five checks comparing the returned data with the frame, the protocol, the recording grid, the allocation and the code list.
  4. A reproducible statistical workflow settles where the seed goes, how paths are written, and what a clean-session render proves.
  5. Testing your analysis code puts a test runner in a screenful of base R and scores it against deliberately planted bugs.
  6. Checking an analysis script asks the three questions a reviewer asks: clean session, same answer twice, and numbers that match what the code computed.
  7. Effect plots that show the data turns a fitted model into the figure a reader can argue with.
  8. Publication-quality ggplot figures is physical size, resolution and export, which is where a good figure is usually lost.

After the course

Forty-four tutorials cover the spine of an analysis and none of the branches. Where you go next depends on your data rather than on your level.

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.