class: center, middle, inverse, title-slide # Accounting for detectability in spatially-explicit abundance models of cetaceans ## University of Sheffield MathBio Seminar ### David L Miller (
@millerdl
) ### 19 February 2018 --- background-size: cover background-image: url(images/sperm_whales_berzin.jpg) --- background-size: cover background-image: url(images/whale_drag.JPG) --- background-size: cover background-image: url(images/whale_penis.JPG) --- # Abundance and distribution: why? - Want to know where they are - whale watching/stock assessments - Want to know where they aren't - Navy/seismic/oil/shipping/fishing etc - Want to know what they like/dislike - ecology/biology --- # How? Big white boats <img src="images/bigwhiteship.png" width=100%> --- <img src="images/observers.png" width=100%> --- class: inverse, middle, center # Can't we just count them all? --- class: inverse, middle, center # Detectability --- # Detectability <img src="images/PaulAllor_perception_bias.png"> --- class: inverse, middle, center # Distribution --- <img src="images/aftt.png"> --- <img src="images/aftt-pokemon.png"> --- class: inverse, middle, center # Example data --- # Sperm whales off the US east coast .pull-left[  ] .pull-right[ - *Physeter catodon/macrocephalus* - Hang out near canyons, eat squid - Surveys in 2004, US east coast - Combination of data from 2 NOAA cruises ] --- <img src="images/data_ships.png"> --- class: inverse, middle, center # Let's talk about detectability --- # Detectability <img src="images/distance-animation.gif" width=900px> --- # Distance sampling - "Fit to the histogram" - Model: $$ \mathbb{P} \left[ \text{animal detected } \vert \text{ animal at distance } y\right] = g(y;\boldsymbol{\theta}) $$ - Calculate the average probability of detection: $$ \hat{p} = \frac{1}{w} \int_0^w g(y; \boldsymbol{\hat{\theta}}) \text{d}y $$ --- # Distance sampling (extensions) * Covariates that affect detectability (Marques et al, 2007) * Perception bias (Burt et al, 2014) * Availability bias (Borchers et al, 2013) * Detection function formulations (Miller and Thomas, 2015) * Measurement error (Marques, 2004) <div align="center"><img src="images/covar-df.png" width=780px></div> <small>Figure from Marques et al (2007)</small> --- # Horvitz-Thompson-like estimators - Rescale the (flat) density and extrapolate $$ \hat{N} = \frac{\text{study area}}{\text{survey area}}\sum_{i=1}^n \frac{s_i}{\hat{p}_i} $$ (where `\(s_i\)` are group/cluster sizes) - Assume flat density - Stratify? --- class: inverse, middle, center # That's not really how the ocean works... --- class: inverse, middle, center # Density surface models Hedley and Buckland (2004) Miller et al. (2013) --- # Modelling process <img src="images/dsm-flow3.png" alt="DSM process flow diagram" width=100%> --- <img src="images/dsmproc.png"> <small>[Physeter catodon by Noah Schlottman](http://phylopic.org/image/dc76cbdb-dba5-4d8f-8cf3-809515c30dbd/)</small> --- class: inverse, middle, center # How do we model that? --- class: inverse, middle, center # SPOILER ALERT: your model is probably just a very fancy GLM --- # Generalised additive models (in 1 slide) Taking the previous example... `$$\mathbb{E}\left(n_j\right) = \color{red}{A_j}\color{blue}{\hat{p}_j} \color{green}{\exp}\left[\color{grey}{ \beta_0 + \sum_k s_k(z_{kj})} \right]$$` `\(n_j\sim\)` some count distribution - `\(\color{red}{\text{area of segment}}\)` - `\(\color{blue}{\text{probability of detection in segment}}\)` - `\(\color{green}{\text{(inverse) link function}}\)` - `\(\color{grey}{\text{model terms}}\)` --- class: inverse, middle, center # What about those s thingys? --- # Covariates - space, time, environmental (remotely sensed) data <!-- --><!-- --> --- # Smooth effects - Assume "smooth" response <!-- --> --- # How do we build them? .pull-left[ <!-- --> ] .pull-right[ - Functions made of other, simpler functions - **Basis functions** `\(b_k\)`, estimate `\(\beta_k\)` - `\(s(x) = \sum_{k=1}^K \beta_k b_k(x)\)` ] --- # Straight lines vs. interpolation .pull-left[ <!-- --> ] .pull-right[ - Want a line that is "close" to all the data - Don't want interpolation -- we know there is "error" - Balance between **interpolation** and **generality** ] --- # Making wigglyness matter - Fit needs to be **penalised** - *Something* like: $$ \int_\mathbb{R} \left( \frac{\partial^2 s(x)}{\partial x^2}\right)^2 \text{d}x\\ $$ - (Can always re-write this in the form `\(\mathbf{\beta}^T \mathbf{S} \mathbf{\beta}\)`) - Estimate the `\(\beta_k\)` terms but penalise objective - "closeness to data" + penalty (REML?) --- # Smoothing parameter <!-- --> --- # How wiggly are things? - We can set **basis complexity** or "size" ( `\(k\)` ) - Maximum wigglyness - Smooths have **effective degrees of freedom** (EDF) - EDF < `\(k\)` - Set `\(k\)` "large enough" <!-- --> --- # Beyond univariate smooths? .pull-left[ <!-- --> ] .pull-right[ - Can build **tensor product** terms - Take 2 or more univariate terms - Can be computationally expensive! ] --- # Thin plate (regression) splines - Isotropic (rotation-invariant) smoothers - Radial basis + global polynomial terms `$$f(x,y) = \sum_{i=1}^n \delta_i \eta(r_i) + \sum_{j=1}^3 \alpha_j \phi_j(x,y)$$` - `\(n\)` = # data `\(\Rightarrow\)` too many parameters! - eigen-decompose model matrix ( `\(X = UDU^\text{T}\)` ) & truncate --- # Smoothing in awkward regions <img src="images/ramsay-leak.png" width=900px> Biologists rarely work on the unit square (or even `\(\mathbb{R}^2\)`). --- # Miller and Wood (2014) <img src="images/msg.png" width=900px> * Calculate within-area distances * Use multidimensional scaling to project * Use Duchon splines for smoothing * Use REML for dimension selection --- # Let's fit a model ```r library(dsm) dsm_env_tw <- dsm(count~s(Depth) + s(NPP) + s(SST), ddf.obj=df_hr, segment.data=segs, observation.data=obs, family=tw()) ``` <img src="images/logo-big.gif" align="left"> <img src="images/mgcv-inside.png" align="right"> --- class: inverse, middle, center # Tobler's first law of geography "Everything is related to everything else, but near things are more related than distant things" Tobler (1970) --- # Implications of Tobler's law <!-- --> --- # Fitting models using robust criteria - GCV performs poorly in presence of concurvity - (GCV has a less well defined minimum in general) - REstricted Maxmimum Likelihood or Marginal Likelihood preferred (Wood, 2011) <br/>  --- # Smooth term selection - (approximate) `\(p\)`-values (Marra & Wood, 2012) - Bayesian uncertainty has good frequentist properties - extra penalty or shrinkage of nullspace (Marra & Wood, 2011) <img src="talk-sheffield_files/figure-html/shrinkie-plot-1.png" width="\textwidth" /> --- # Double-penalty shrinkage `$$\mathbf{S}_j = \mathbf{U}_j\mathbf{\Lambda}_j\mathbf{U}_j^{T}$$` `\(\mathbf{\Lambda}_j\)` contains **0**s due to basis nullspace Form: `$$\mathbf{S}_j^{*} = \mathbf{U}_j^{*}\mathbf{U}_j^{*T}$$` Fit a GAM with two penalties: `$$\lambda_j \mathbf{\beta}^T \mathbf{S}_j \mathbf{\beta} + \lambda_j^{*} \mathbf{\beta}^T \mathbf{S}_j^{*} \mathbf{\beta}$$` (In practice, add `select = TRUE`) --- # Empirical Bayes...? - Penalty is a prior precision matrix - **but** it's improper as it's not full rank - Extra shrinkage makes priors proper! - Shrinkage: assume nullspace should be shrunk less than the wiggly part - Double penalty: no assumption as to how much to shrink the null space `\(\Rightarrow\)` fit GAMs using general MCMC software (`JAGS`, `greta` etc) --- class: inverse, middle, center # Inference --- # Predictions over arbitrary areas .pull-left[ <!-- --> ] .pull-right[ - Don't want to be restricted in where to predict - Predict within survey area - Extrapolate outside (with caution) - Working on a grid of cells ] --- class: inverse, middle, center # Okay, but we're actually doing statistics... --- # Bootstraps are a bad idea - Where there is no effort, resamples underestimate uncertainty - Use distributional results `\(\boldsymbol{\beta}\vert \mathbf{y}, \boldsymbol{\lambda} \sim N(\boldsymbol{\hat{\beta}}, \mathbf{V}_\boldsymbol{\beta})\)` <img src="images/bootinbootstraps.png" width="70%"> --- # Variance propagation - 2-stage model! Need to propagate uncertainty! - Refit model with "extra" term `$$n_j = A_j p_j \exp \left\{ \color{red}{\left[\frac{ \partial \log p_j(\boldsymbol{\theta})}{\partial\boldsymbol{\theta}} \Big\vert_{\boldsymbol{\theta} = \hat{\boldsymbol{\theta}}}\right] \boldsymbol{\gamma}} + \beta_0 + \sum_k f_k(z_{jk}) \right\}$$` - *random effect* -- fix the corresponding covariance matrix `\(\boldsymbol{\gamma} \sim N(0,-\mathbf{H}^{-1}_\theta)\)` - Bravington, Hedley & Miller (in prep) --- # Plotting uncertainty .pull-left[ <!-- --> ] .pull-right[ - Maps of coefficient of variation (probably biased?) - CV for given stratum (better) - This is **hard** ] --- # Communicating uncertainty .pull-left[  ] .pull-right[ - Are animations a good way to do this? - Simulate from posterior parameter distribution - `\(\boldsymbol{\beta}\vert \mathbf{y}, \boldsymbol{\lambda} \sim N(\boldsymbol{\hat{\beta}}, \mathbf{V}_\boldsymbol{\beta})\)`- Some features (e.g. shelf, N-S gradient) stick out ] --- class: inverse, middle, center # Availability --- # We can only see whales at the surface - What proportion of the time are they there? - Acoustics - Tags (DTAGs etc) - Behavioural studies - Fixed correction to `\(\hat{p}\)`? - Model via fancy Markov models (Borchers et al, 2013)  <small>Picture from University of St Andrews Library Special Collections</small> --- class: inverse, middle, center # I am going to stop talking very soon --- # 2 (or more)-stage models - Not "cool" but... - Current point process models are not as feature rich - Multi-stage models are handy! - Understand and **check** each part - Split your modelling efforts amongst people --- # Current challenges .pull-left[ - US Navy has funded St Andrews/Duke/NOAA for developments (4 years) - Year 1 tasks: - Uncertainty - Model unification - Extrapolation - Tools ] .pull-right[ <img src="images/lmr.png"> ] --- # Conclusions - This methodology is general - Bears, birds, beer cans, Loch Ness monsters... - Models are flexible! - Linear things, smooth things, random effect things (and *more*) - If you know GLMs, you can get started with GAMs/DSMs - Mature theoretical basis, still lots to do - Active user community, active software development - `Distance`, `dsm`, `mrds` - "Distance Sampling in R" on bioRxiv/JSS --- # Acknowledgements - St Andrews: Eric Rexstad, Len Thomas, Louise Burt, Laura Marshall, Steve Buckland, Sharon Hedley - Duke: Jason Roberts, Laura Mannocci - CSIRO: Mark Bravington - Australian Antarctic Division: Nat Kelly - Funding: University of St Andrews, State of Rhode Island, US Navy, NOAA, International Whaling Commission --- # Resources  [distancesampling.org/R/](http://distancesampling.org/R/) [workshops.distancesampling.org](http://workshops.distancesampling.org) --- class: inverse, middle, center # Thanks! Slides w/ references available at converged.yt --- # References <div style="font-size:45%"> Borchers, DL, Zucchini, W, Heide-Jørgensen, MP., Cañadas, A, Langrock, R, Buckland, ST, & Marques, TA (2013). Using hidden Markov models to deal with availability bias on line transect surveys. Biometrics, 69(3). <br/> Burt, ML, Borchers, DL, Jenkins, KJ, & Marques, TA (2014). Using mark-recapture distance sampling methods on line transect surveys. Methods in Ecology and Evolution, 5(11). <br/> Hedley, SL, & Buckland, ST (2004). Spatial models for line transect sampling. Journal of Agricultural, Biological, and Environmental Statistics, 9(2). <br/> Marques, TA (2004). Predicting and correcting bias caused by measurement error in line transect sampling using multiplicative error models. Biometrics, 60(3). <br/> Marques, TA, Thomas, L, Fancy, SG, & Buckland, ST (2007). Improving estimates of bird density using multiple-covariate distance sampling. The Auk, 124(4). <br/> Marra, G, & Wood, SN (2011). Practical variable selection for generalized additive models. Computational Statistics and Data Analysis, 55(7). <br/> Marra, G, & Wood, SN (2012). Coverage Properties of Confidence Intervals for Generalized Additive Model Components. Scandinavian Journal of Statistics, 39(1). <br/> Miller, DL, Burt, ML, Rexstad, EA, & Thomas, L (2013). Spatial models for distance sampling data: recent developments and future directions. Methods in Ecology and Evolution, 4(11). <br/> Miller, DL, Rexstad, EA, Thomas, L, Marshall, LH, and Laake, JL (????) Distance Sampling in R. Accepted at the Journal of Statistical Software. <br/> Miller, DL & Thomas, L (2015). Mixture models for distance sampling detection functions. PLoS ONE. </div>