Building ecological models bit-by-bit

David L Miller
CREEM, University of St Andrews

useR! 2015
Ålborg, Denmark
1 July 2015






Motivation

Ecological questions

How many animals are there?

How?

Statistical methods

(Usable by ecologists)

Software

(Usable by ecologists)

Proposal

Case study:
distance sampling

Distance sampling (in 1 slide)

Code for animation at https://gist.github.com/dill/2b0c120d5484d338d8ef

Modelling detection

\[ \hat{p}_i = \frac{1}{w} \int_0^w g(y; \mathbf{z}_i, \boldsymbol{\hat{\theta}}) \text{d}y \]

\[ \hat{N} = \sum_{i=1}^n \frac{s_i}{\hat{p}_i} \]

Detection function

Mark-recapture distance sampling

\[ \mathcal{L} = \mathcal{L}_g \mathcal{L}_\Omega \]

Mark-recapture distance sampling animation

Code for animation at https://gist.github.com/dill/2b0c120d5484d338d8ef

Partition in likelihood == partition in software

Syntax example

library(Distance2)
# MR model
mr.io <- mrds(data, truncation=4,
              model=mr(mode="io", formula=~distance))
## do checking of mr part

# DS model
ds1 <- ds(data, truncation=4)
## do checking of ds part

# "add" them together
mrds.io <- mr.io + ds1

+ is a really useful operator

Let + do the work

“Inspired” (“stolen”) from ggplot2

Can we do this for other model classes?

Something like…?

# linear model
mod <- lm(response ~ x1, data=data)
mod <- mod + lm_var(x2)

less trivially

# include correlation structure in nlm
library(nlm)
mod <- nlm(response ~ x1, data=data)
mod_AR1 <- mod + corAR1(form=~sample|group)

Refit using nlm starting parameters? See also update.

Conclusion

Thanks!

Talk available:
http://converged.yt/talks/useR2015/talk.html

References