rbchan / unmarked

R package for hierarchical models in ecological research
https://rbchan.github.io/unmarked/
37 stars 25 forks source link

Fit time-to-detection occupancy models #144

Closed kenkellner closed 4 years ago

kenkellner commented 4 years ago

Adds a new fitting function occuTTD, which fits time-to-detection occupancy models (inspired by Jonathan Cohen's recent post on the listserv, https://groups.google.com/forum/#!topic/unmarked/jAkuA0z_aGc).

You can fit models where there is a single survey per site, or multiple surveys per site (e.g., multiple observers). You can also fit dynamic models, with the same interface as colext. Time to detection can be modeled with an exponential or Weibull distribution.

Here's an example fitting the TTD model in AHM, chapter 10:

#AHM Example 10.12.1, page 616-617

library(AHMbook)
library(unmarked)

set.seed(1)
data <- simOccttd()

#Unmarked requires censored values = Tmax
y = data$ttd
y[is.na(y)] <- data$Tmax

sc <- data.frame(covB=data$covB)
oc <- data.frame(covA=data$covA)

umf <- unmarkedFrameOccuTTD(y=y, surveyLength=data$Tmax,
                            siteCovs=sc, obsCovs=oc) 

fit <- occuTTD(psiformula=~covB, detformula=~covA, data=umf)

fit

#For comparison of estimates to Bayesian model (pg 617), need to do some transforms
ests <- coef(fit)
ests[1] <- plogis(ests[1]); ests[3] <- exp(ests[3])
ests

#Plot predicted first detection time vs. covariate
rng <- range(data$covA)
rng_covA <- seq(rng[1],rng[2],length.out=100)
pr_ttd = 1/predict(fit, 'det', newdata=data.frame(covA=rng_covA))$Predicted
pr_ttd[pr_ttd > data$Tmax] <- data$Tmax
plot(rng_covA, pr_ttd, ylab="TTD", type='l', xlab="Covariate A")
points(data$covA, data$ttd,  col='red')
rbchan commented 4 years ago

@kenkellner Great stuff! We should plan on releasing a new version soon. When you're ready, would you add to the NEWS, and bump the version number?

kenkellner commented 4 years ago

Will do. I want to do a little cleanup on some C++ functions first but then everything should be ready for a release.