BIO144 · FS 2027 · Unit 11, part 2

Expand your mind: what next?

Data analysis beyond BIO144

Prof. Owen Petchey · University of Zurich

BIO144 Data Analysis in Biology logo
Look how far you've come

What you can already analyse

Units 3–7

Linear models

Data that meet their assumptions: regression, ANOVA, several explanatory variables, interactions.

Units 8–9

GLMs

Count data and binary data.

Unit 11

Mixed models

Grouped or repeated-measures data.

Unit 10

Ordination

Many variables at once.

That's a lot. And there is much more to learn.

Think · Pair · Share

What kind of data, or question, might you meet that BIO144 can't handle?

Klicker
Beyond BIO144

Twelve situations, twelve families of methods

Tap one to jump to it

Not an exhaustive list. For each: what's the situation, what's the method, and where to start in R.

SituationI have a series of values through time

Time series analysis

Observations close in time are usually similar: they are not independent, which breaks an assumption of most standard methods. Time series methods (e.g. ARIMA, seasonal decomposition, forecasting) handle this.

In R: acf() forecast rEDM
Weekly case counts of a disease through time in three places, with their power spectraDisease cases through time. Rozhnova, G., Metcalf, C.J.E. & Grenfell, B.T. (2013) Characterizing the dynamics of rubella relative to measles: the role of stochasticity. J. R. Soc. Interface, 10.
SituationMy data points are distributed in space, and I have their locations (e.g. latitude and longitude)

Spatial analysis

Nearby points tend to be similar (spatial autocorrelation), so again observations are not independent. Methods include spatial regression, kriging and geostatistics.

In R: the Spatial CRAN Task View
Map of a region with points coloured by population sizePoints with locations: resident population across a region.
SituationThe relationship I would like to fit between two continuous variables is curvy!

Nonlinear regression

Estimate the parameters of a specific non-linear function, such as logistic growth, f(x) = L / (1 + e−k(x−x₀)), and assess how well it fits.

In R: nls() (base R)
Growth curve of a bacterial culture: lag, logarithmic growth, stationary and death phasesPhases of growth of a bacterial population.
SituationThe relationship between two continuous variables may have a discontinuity!

Segmented, piecewise or breakpoint regression

The relationship changes at some point, e.g. before and after an intervention, or once a threshold is passed. Estimate where the break is, and the relationship on each side.

In R: segmented
Two scatterplots of transpiration ratio against soil water, flat then dropping sharply below a breakpointNormalised transpiration ratio vs fraction of transpirable soil water. Fuentealba, M.P. et al. (2016) Transpiration responses of warm-season turfgrass in relation to progressive soil drying. Scientia Horticulturae, 198, 249–253.
SituationI don't know, and don't care, what function to fit between my two continuous variables, but I do want one!

Generalised additive models (GAMs)

Smooth functions capture non-linear effects, while the model stays interpretable. They extend the GLMs you know. Rather elegant!

In R: mgcv
Scatterplot with a smooth wiggly fitted line and its confidence bandA smooth fitted through noisy data, with its uncertainty.
SituationI have a network, a system, of variables

Path analysis and structural equation modelling (SEM)

Variables can be explanatory and response at the same time. Model direct and indirect effects, even latent variables: build and test causal models.

In R: sem lavaan
Diagram of multiple regression: four explanatory variables each point to one responseMultiple regression: every arrow goes to one response.
Path diagram in which some variables affect others that in turn affect further variablesA path model: some variables are both causes and effects.
SituationI just want to predict…

Machine learning

Decision trees, random forests, support vector machines, neural networks… They make predictions or classify, can handle large datasets and complex relationships, but may sacrifice interpretability.

install.packages(c(
  "ranger",   # random forests
  "xgboost",  # gradient boosting
  "glmnet",   # lasso/ridge/elastic net
  "kernlab",  # support vector machines
  "kknn",     # k-nearest neighbours
  "earth",    # adaptive regression splines
  "nnet"      # simple neural networks
))
SituationI'm reviewing and analysing the results of many studies

Meta-analysis

Combine the effect sizes from different studies to draw broader conclusions, and assess how much they differ (heterogeneity). Another reason to report effect sizes (Principle 3).

In R: metafor (and others)
Forest plot: hazard ratio and confidence interval for each of five studies, and the combined estimateA forest plot: one estimate per study, and the combined estimate (diamond). Oba, K. et al. (2009) Individual patient based meta-analysis of lentinan for unresectable/recurrent gastric cancer. Anticancer Research, 29, 2739–45.
SituationMy response variable is the amount of time until something happened

Survival analysis

Time-to-event data: time until death, failure, germination, flowering… Some individuals haven't had the event by the end of the study (censoring). Kaplan–Meier curves, Cox proportional hazards models.

In R: survival (and others)

type: tumour DNA profile (1 aneuploid, 2 diploid) · time: weeks to death or end of study · delta: 0 alive, 1 dead

Table of data with columns type, time and delta
Two survival curves: proportion alive against time for two tumour typesProportion alive through time, for the two tumour types.
SituationI can't fix my residuals

Nonparametric methods

Rank-based tests, bootstrapping and permutation tests make fewer assumptions about the distribution of the data.

In R: base R, e.g. kruskal.test() (and other packages)

Kruskal–Wallis is somewhat equivalent to a one-way ANOVA, on the ranks of the data.

But first: can you make a model that fits, e.g. a transformation, or a GLM with a suitable distribution (Principle 2)?

SituationI want to make sure my planned experiment has adequate statistical power

Power analysis

Power is the probability of detecting an effect if it is really there. It depends on the effect size, the variation, the number of observations and the significance level. Use it to work out the sample size you need, before you collect data.

In R: pwr
Try it: comparing two groups
Power
Per group for 80% power

d = difference in means divided by the standard deviation. Normal approximation to a two-sample t-test.

SituationI have some prior information

Bayesian statistics

Combine prior knowledge with the data, using Bayes' theorem: P(H | E) = P(E | H) P(H) / P(E). The result, the posterior, describes what we believe after seeing the data, with its uncertainty.

In R: rstan R-INLA rjags · Book: Statistical Rethinking (McElreath)
Try it: what proportion of seeds germinate?

Some methods are not mutually exclusive

Combined

Repeated measures through time: mixed models and time series. Counts across space: GLMs and spatial methods.

Extended

GAMs extend GLMs. Mixed models can be GLMs (GLMMs).

Bayesian versions

Bayesian methods can be used for most of them.

And there are multiple books about each.

Your turn

Which family of methods?

Two pieces of advice

1 · Plan ahead

Plan the analysis when you design the study

Including the sample size you need (power analysis). Then you collect the right data to answer your question. When something changes, explore the options and talk to experts.

2 · Question first

Be driven by your questions, not by techniques

We don't analyse data for its own sake, but to answer questions about the world. Let your questions guide what you learn next.

Principle 1 from Week 1: a focused question first, then plan sampling and analysis to answer it.

Where to start learning more

CRAN Task Views

Curated lists of R packages, by topic:

TimeSeries Spatial MachineLearning MetaAnalysis Survival Bayesian Psychometrics (SEM) ExperimentalDesign Environmetrics
cran.r-project.org/web/views

Statistical Rethinking

Richard McElreath's book on multilevel Bayesian modelling, with free lecture videos.

The course book

Chapter 11.2 lists all twelve, with what each is for.

People

Statisticians, and colleagues who use the methods. Ask early.

SituationI want to work as a data scientist or analyst, and make lots of money

A recruiter in quantitative finance and technology told me: after a science Masters or PhD, the most common first job was quantitative researcher, quantitative analyst or data scientist. The skills asked for:

  • machine learning (over the past few years, a must)
  • working with large datasets: manipulation and visualisation
  • programming, e.g. Python; research languages such as R
  • time series analysis and forecasting

We do all of these in my ecology group :)

Machine learning, time series analysis, forecasting

Listening: Data Analytics in the Liberal Arts; How to Build Analytics Technical Skills (How to Get an Analytics Job podcast).

R and RStudio evolve

Screenshot of the plain R console and script windowsThen: R on its own.
Screenshot of RStudio with script, console, environment and files panesNow: RStudio, the tidyverse, the native pipe |>, Quarto…

So do the books: Getting Started with R (Beckerman & Petchey 2012; 2nd ed. with Childs, 2017), Insights from Data with R (Petchey et al. 2021). Keep learning, and keep updating.

Statistical methods and thinking evolve too

Ordinary multiple regression was once considered cutting edge: something only experts would fiddle with.

Paraphrasing Richard McElreath, Statistical Rethinking.

Today's specialist method (e.g. multilevel Bayesian modelling) may be tomorrow's standard tool.

Finally

Can all problems be solved with data and analyses?

Necessary, but not sufficient. Think of the UN Sustainable Development Goals: poverty, hunger, health, climate, life on land and in water.

And “we need more data before we act” is often no longer a good argument.

Until next week…

Before Monday

Tell us

Post on the OLAT forum what you'd like to go over in the review.

Mon 31 May

Unit 12: Review

Planning and implementing statistical analyses.

Fri 4 June

Last practical

The only practical that week: the Thursday group comes on Friday.

Fri 18 June

Final exam

10:00–12:00. Mandatory Probeprüfung before then.