Accessible version · How to use this site with a screen reader · Course home
Day 5 · Accessible lecture notes

Bayesian statistics II

A screen-reader-friendly transcript of the lecture slides: all slide text, tables, figure descriptions, and speaker notes.

About these notes

Each section is one slide. Figures carry text descriptions where available. For the concepts with worked examples, also read the plain-language summary and lab for this session.

Slide 1

Introduction to Bayesian Analysis Part Deux

Figure 1.1. 3D surface plot of a bivariate normal probability density over axes x1 and x2, showing a bell-shaped peak (~0.15) at the origin, with a semi-transparent horizontal reference plane.

Many slides adapted from Matt Falcy ODFW, and SESYNC course by Chris Che-Castaldo, Mary B. Collins, N. Thompson Hobbs (with permission)

Figure 1.2. Portrait of Thomas Bayes with Bayes' theorem overlaid. Equation: P(A|B) = P(B|A) P(A) / P(B).

Slide 2: Where to go from here

Figure 2.1. Book cover: 'Statistical Rethinking: A Bayesian Course with Examples in R and Stan,' Second Edition, by Richard McElreath.
Figure 2.2. Screenshot of two YouTube playlists by Richard McElreath: Statistical Rethinking 2023 (20 videos) and 2022 (21 videos), with a woodpecker thumbnail.

Slide 3: Where to go from here

Figure 3.1. Book cover: 'The Theoretical Biologist's Toolbox: Quantitative Methods for Ecology and Evolutionary Biology' by Marc Mangel.
Figure 3.2. Book cover: 'The Ecological Detective: Confronting Models with Data' by Ray Hilborn and Marc Mangel, Monographs in Population Biology 28.

Slide 4: This course is just a jumping off point

Figure 4.1. Book cover: 'The Ecological Detective: Confronting Models with Data' by Ray Hilborn and Marc Mangel, Monographs in Population Biology 28.
Figure 4.2. Book cover: 'Ecological Models and Data in R' by Benjamin M. Bolker, showing a fish on coral.
Figure 4.3. Book cover: 'The Theoretical Biologist's Toolbox: Quantitative Methods for Ecology and Evolutionary Biology' by Marc Mangel.
Figure 4.4. Book cover: 'Applied Hierarchical Modeling in Ecology' Volume 1, by Marc Kery and J. Andrew Royle, with a green dragonfly.
Figure 4.5. Book cover: 'Applied Hierarchical Modeling in Ecology' Volume 2, Dynamic and Advanced Models, by Marc Kery and J. Andrew Royle, with a red dragonfly.
Figure 4.6. Book cover: 'Bayesian Models: A Statistical Primer for Ecologists' by N. Thompson Hobbs and Mevin B. Hooten.

Slide 5

Figure 5.1. [β0, β1, σ | y] ∝ ∏i=1N normal(yi | g(β0, β1, xi), σ²) × normal(β0 | 0, 1000) normal(β1 | 0, 1000) × uniform(σ | 0, 100) g(β0, β1, xi) = β0 + β1 xi b0 ~ dnorm(0, .001) b1 ~ dnorm(0, .001) sigma ~ dunif(0, 100) tau <- 1/sigma^2 for (i in 1:length(y)){ mu[i] <- b0 + b1 * x[i] y[i] ~ dnorm(mu[i], tau) }

Slide 6

Figure 6.1. Slide titled 'Nonlinear regression'; the embedded figure did not render, only a citation to Bolker 2008, Ecological Models and Data in R.

Slide 7

Figure 7.1. Scatterplot of Recruits versus Spawners with a curved black Beverton-Holt fit that saturates near 4000-4500 recruits, and a blue 1:1 replacement line.

Neq

Smsy

Hmsy

Figure 7.2. R code for derived quantities: Neq <- b*(a-1)/a; Smsy <- b*sqrt(1/a) - b/a; Hmsy <- 1 - sqrt(1/a).

How would you estimate these with uncertainty in frequentist framework?

Slide 8

Figure 8.1. Table 'You don't have to be normal!' mapping data types to distribution, mean function, and link: continuous/normal (identity), discrete-positive/Poisson (log), 0-or-1/Bernoulli (logit), [0,1]/beta (logit), positive/lognormal and gamma (log).

Wrong→

Slide 9

Figure 9.1. [β0, β1 | y] ∝ ∏i=1N Poisson(yi | g(β0, β1, xi)) × normal(β0 | 0, 1000) normal(β1 | 0, 1000) g(β0, β1, xi) = exp(β0 + β1 xi) b0 ~ dnorm(0, .001) b1 ~ dnorm(0, .001) for(i in 1:length(y)){ log(mu[i]) <- b0 + b1 * x[i] y[i] ~ dpois(mu[i]) } or mu[i] <- exp(b0 + b1 * x[i]) y[i] ~ dpois(mu[i])

Slide 10

Figure 10.1. Bernoulli, 0 or 1 (aka logistic) [β0, β1 | y] ∝ ∏i=1N Bernoulli(yi | g(β0, β1, xi)) × normal(β0 | 0, 2.7) normal(β1 | 0, 2.7) g(β0, β1, xi) = exp(β0 + β1 xi) / (exp(β0 + β1 xi) + 1) b0 ~ dnorm(0, .37) b1 ~ dnorm(0, .37) for(i in 1:length(y)){ logit(p[i]) <- b0 + b1 * x[i] y[i] ~ dbern(p[i]) } or p[i] <- inv.logit(b0 + b1 * x[i]) y[i] ~ dbern(p[i])

Lizard Occurrence on Islands

Slide 11

Hierarchical Models

Hierarchical models are very natural in a Bayesian framework

Slide 12

Figure 12.1. Slide text: Clark 2003 modeled fecundity of spotted owls and its implications for population growth; data were offspring counts per pair of owls, sample size n=197.

Slide 13

Figure 13.1. Directed graph with arrows from alpha and beta pointing to lambda_i. Equation: [lambda,alpha,beta|y] proportional to product Poisson(y_i|lambda_i) gamma(lambda_i|alpha,beta) times gamma(alpha|.001,.001) gamma(beta|.001,.001).

Gamma is the conjugate prior and flexible/non-negative. Good choice here

#offspring per pair of owls

Slide 14

Figure 14.1. Directed graph with arrows from alpha and beta pointing to lambda_i. Equation: [lambda,alpha,beta|y] proportional to product Poisson(y_i|lambda_i) gamma(lambda_i|alpha,beta) times gamma(alpha|.001,.001) gamma(beta|.001,.001).

Gamma is the conjugate prior and flexible/non-negative. Good choice here

Every individual has one of these

But they arise from a common distribution

Slide 15

MULTILEVEL MODELING

Soil nitrous-oxide emissions are measured at multiple sites across the world. Each site has multiple measurements of (nitrogen input, emission). Different sites have wildly different soil organic carbon, climate, and microbial communities — so we expect site-level structure.

Slide 16

Complete pooling

Figure 16.1. JAGS complete-pooling model code: single alpha and beta priors, sigma, and one likelihood loop regressing log.emission on centered log nitrogen input, plus a loop deriving predicted emissions.

Iterate likelihood over the data

Only one alpha and beta

Only one alpha and beta

Slide 17

No pooling

Figure 17.1. JAGS no-pooling model code: a separate alpha[j] prior for each of n.sites, shared beta and sigma; likelihood uses alpha[group[i]], with nested loops for site-level predicted emissions.

Every site gets its own alpha

Slide 18

Figure 18.1. Directed acyclic graph for a partial-pooling random-intercept model: y_ij depends on beta, alpha_j, sigma, and covariate x_ij; alpha_j depends on hyperparameters mu_alpha and varsigma_alpha.
Figure 18.2. JAGS partial-pooling model code: hyperpriors mu.alpha and sigma.alpha, site intercepts alpha[j] drawn from dnorm(mu.alpha, tau.alpha), shared beta/sigma, likelihood, and predicted emissions loops.

Alpha varies by site but within shared distribution

Slide 19

Figure 19.1. JAGS model code adding a site-level carbon covariate: mu.alpha[j] <- kappa + eta*w[j] and alpha[j] ~ dnorm(mu.alpha[j], tau.alpha), explaining variation in intercepts among sites, plus predicted emissions.

Every site gets its own alpha

Figure 19.2. Directed acyclic graph: y_ij depends on alpha_j, beta, sigma, and covariate x_ij; alpha_j depends on kappa, eta, varsigma_alpha, and site covariate w_j feeds into alpha_j.

In the previous example, we assumed that the variation in the intercept was attributable to spatial variation among sites. We did not try to explain that variation, we simply acknowledged that it exists. Now we are going to “model a parameter” using soil carbon content data at the site-level to explain variation in the intercepts among sites.

Alpha varies by site but within shared distribution

Flexibility! Intercepts can depend on soil carbon

Slide 20

Latent Variable Modeling I - Occupancy

Figure 20.1. Tree diagram of occupancy detection: surveying an area leads to not seeing the species (y=0), which means either absent (z=0) or present but undetected (z=1); or seeing it (y=1), meaning present (z=1).

“Latent variable” inferred rather than observed

What should the priors be?

Slide 21

Figure 21.1. Slide 'Choosing reasonable flat priors on logit intercept.' Four panels: a normal(0, var=10000) prior on logit(p) gives a U-shaped bathtub distribution of p (mass at 0 and 1), while normal(0, var=2.7) gives a roughly uniform p.

Slide 22

DYNAMIC OCCUPANCY MODELING LAB

Figure 22.1. Diagram of dynamic occupancy transitions from year t-1 to year t between states z=0 (absent) and z=1 (present), with rates: colonization gamma, persistence phi, and complements 1-gamma and 1-phi.

Slide 23

Figure 23.1 — needs description This slide contains an image not yet described in text. Instructor: add a description.