Linear Modelling

Bayesian Methods for Ecological and Environmental Modelling

Peter Levy
UKCEH Edinburgh

What we will cover

2-3.30 pm: Session 3 Linear modelling - part 1

  • Recap basics & MCMC
  • Review different kinds of systems & models
  • Linear models - terminology, theory & assumptions
  • Practical 3a: Use MCMC with simple linear models

3.30-4 pm: Tea & coffee break

4-5 pm: Session 3 Linear modelling – part 2

  • Practical 3b: Linear models with informative priors

Recap - Bayesian basics

Science and Models

The core of the scientific process involves:

  • formulating models of how the world works
  • comparing with data to assess their validity

Inference is the process of estimating models, parameters, and their uncertainties, using data

  • how we go from evidence to a conclusion

Terminology

  • hypothesis = a statement of how a system works
    • e.g. CO\(_2\) causes global warming
  • model = mathematical representation of how a system works
    • e.g. Temperature = f(CO\(_2\))
  • parameter = numerical constant within a model
    • e.g. \(T = \beta CO_2\)
    • true value unknown, but estimated with uncertainty

Bayesian inference

The mathematically correct way to do inference with conditional probability

  • estimate parameters \(\theta\) from data \(y\)
  • only really feasible with modern computers
  • posterior \(\propto\) prior \(\times\) likelihood
  • \(P(\theta | y) \propto P(\theta) P(y | \theta)\)

Likelihood and probability

Likelihood” and “probability” used interchangeably in common speech.

Likelihood has a specific meaning in statistics:

  • parameters have a likelihood:
  • \(L[\mu, \sigma] = P[\mathrm{data} | \mu, \sigma]\)
  • equal to the probability of the data, given those parameters

“Classical”/“frequentist” statistics

  • an ad hoc invention of the 1920s
  • easy to compute for Gaussian data, often similar answers, BUT:
  • restricted to simple models
  • quantifying uncertainty is hard
  • encourages misguided mindset

Markov Chain Monte Carlo (MCMC)

  • general method for how to implement Bayesian inference
  • samples the unknown distribution of \(\theta\)
    • using known likelihood function

Next:

  • review different kinds of systems / models
  • apply MCMC to simple linear models

Types of systems and models

Four types of system

  1. Stable
  2. Periodic
  3. Chaotic
  4. Complex

Stable systems

  • example: fertiliser & crop yield, carbon content in soil
  • at steady state or moves towards equilibria
  • domain of statistical & process modelling

Periodic systems

  • examples: predator-prey populations, thermostat
  • interactions and feedbacks
  • move in repeating patterns
  • domain of dynamic modelling & ODEs
  • \(dy/dt = f(x, \cdots)\)
  • \(dx/dt = f(y, \cdots)\)

Chaotic systems

  • examples: dice roll, turbulence, weather
  • sensitivity to initial conditions
  • rapidly become unpredictable
  • difficult to model directly
    • but we can model statistical properties

Complex systems

  • examples: food webs, ecosystems, the economy
  • assemblages of interacting systems
  • predictability depends on relative stability, feedbacks & chaotic behaviour

Four types of model

  1. Empirical: \(y = f(\theta, x)\)
  2. Statistical: \(y = f(\theta, x) + \epsilon\)
    • \(\theta\) and \(\epsilon\) inferred from measurements of \(y\) and \(x\)
    • commonly uses linear models and ordinary least squares
  3. Machine Learning: \(y = f(\theta, x) + \epsilon\)
    • form of \(f\) and \(\theta\) inferred from measurements of \(y\) and \(x\)

Four types of model

  1. Process-based / mechanistic: \(y = f(\theta, x)\)
    • \(f\) is based on causal understanding, often nonlinear
    • \(\theta\) inferred from measurements of \(y\) and \(x\)
    • calibration often informal; \(\epsilon\) not explicit

Four types of model

  1. Process-based / mechanistic: \(y = f(\theta, x)\)
    • \(f\) is based on causal understanding, often nonlinear
    • \(\theta\) inferred from measurements of \(y\) and \(x\)
    • calibration often informal; \(\epsilon\) not explicit

Bayesian approach applies to all types of systems and models (in principle)

Stable systems Linear models

Terminology

  • Linear Models
  • Linear Regression
  • Regression modelling
  • the General Linear Model includes:
    • t-test
    • ANOVA
    • multivariate regression

We want to predict one thing (y) on the basis of another (x)

Terminology

  • y: response, outcome, dependent variable
  • x: predictor, covariate, independent variable - used to help understand the variability in the response

Linear model

A function that describes a linear relationship between the response, \(y\), and the predictor, \(x\).

\[\begin{aligned} y &= \color{black}{\textbf{Model}} + \text{Error} \\[6pt] &= \color{black}{\mathbf{f(\theta, x)}} + \epsilon \\[6pt] &= \mathrm{intercept} + \mathrm{slope} \cdot x + \epsilon \\[6pt] &= \alpha + \beta x + \epsilon \\[6pt] \theta &= (\alpha, \beta) \\[6pt] \end{aligned}\]

Linear model

A function that describes a linear relationship between the response, \(y\), and the predictor, \(x\).

\[\begin{aligned} y &= \color{black}{\textbf{Model}} + \text{Error} \\[6pt] &= \color{black}{\mathbf{f(\theta, x)}} + \epsilon \\[6pt] &= \mathrm{intercept} + \mathrm{slope} \cdot x + \epsilon \\[6pt] &= \beta_0 + \beta_1 x + \epsilon \\[6pt] \theta &= (\beta_0, \beta_1) \\[6pt] \end{aligned}\]

Linear model

\[ \begin{aligned} y &= \color{purple}{\textbf{Model}} + \text{Error} \\[8pt] &= \color{purple}{\mathbf{f(\theta, x)}} + \epsilon \\[8pt] &= \color{purple}{\alpha + \beta x} + \epsilon \\[8pt] \end{aligned} \]

Linear model + residual error

\[\begin{aligned} y &= \color{purple}{\textbf{Model}} + \color{blue}{\textbf{Error}} \\[8pt] &= \color{purple}{\mathbf{f(\theta, x)}} + \color{blue}{\boldsymbol{\epsilon}} \\[8pt] &= \color{purple}{\alpha + \beta x} + \color{blue}{\boldsymbol{\epsilon}} \\[8pt] \end{aligned}\]

Linear model + residual error

\[\begin{aligned} y &= \color{purple}{\textbf{Model}} + \color{blue}{\textbf{Error}} \\[8pt] &= \color{purple}{\mathbf{f(\theta, x)}} + \color{blue}{\boldsymbol{\epsilon}} \\[8pt] &= \color{purple}{\alpha + \beta x} + \color{blue}{\boldsymbol{\epsilon}} \\[8pt] \end{aligned}\]

Uses

  • Prediction
  • Extrapolation
  • Associations / correlation
  • Causal inference

Terminology

Regression slopes \(\beta\) are often referred to as effects

  • e.g. \(\beta = 1.5\) is the numerical effect of \(x\) on \(y\) in the model
  • but effect implies causality
  • better called coefficient to be neutral

Frequentist linear regression

  • find the best-fit line which minimises residuals
  • point estimate for the relationship between x and y
  • assume Gaussian approximation for confidence intervals
  • test null hypothesis of zero slope \(\beta = 0\)

Bayesian linear regression

  • find the (posterior) distribution of plausible relationships between x and y
    • i.e. \(P(\theta | y) \propto P(\theta) P(y | \theta)\)
  • use Bayes rule via MCMC
  • no Gaussian assumption needed for parameters (only measurement error)
  • hypothesis test is irrelevant - posterior \(\theta\) captures all information

Assumptions

  • Linearity
  • 0 zero error in \(x\)
  • Independent samples
  • Normally-distributed measurement error
  • Constant variance across the range in \(x\)
  • loth to forget these
  • mnemonic: L0INCloth

Extensions to Linear Modelling

When the assumptions are not met …

  • Linearity - Generalised Linear Models; General Additive Models
  • 0 zero error in \(x\) - uncertainty propagation by MC simulation
  • Independent samples - hierarchical & mixed-effect models; spatial/time series
  • Normally-distributed measurement error - Generalised Linear Models

Theory into practice …

Two practicals

  • Bayesian estimation of the parameters of linear models
  • use package in R for MCMC rstanarm
    • easy syntax for specifying model

Consider:

  • convergence checks
  • model predictions
  • prior distributions

Tree allometry

How does tree mass scale with stem diameter? Can we reliably estimate forest carbon stocks from simple measurements?

Tree allometry

How does tree mass scale with stem diameter? Can we reliably estimate forest carbon stocks from simple measurements?

Space Shuttle Challenger

How do we assess risks from uncertain linear relationships? How do we combine data with prior knowledge?

Syntax

m <- lm(tree_mass ~ basal_area, data = df)

m <- stan_glm(tree_mass ~ basal_area, data = df)