WinBUGS Modeling Code and Notes for ZIA Incomplete Detection Models (Wenger and Freeman Ecology 2008). The following code, with simulated sample data and priors, may be pasted directly into a blank window in WinBUGS. This was tested on WinBUGS 1.4 (Spiegelhalter et al. 2003). This is a simple version assuming constant detection and a zero-inflated Poisson abundance model. It can be readily extended to allow variable detection, but zero-inflated negative binomial models are more challenging because the built-in negative binomial function of WinBUGS requires that the “r” parameter be an integer, rather than a continuous number, which yields results inconsistent with other modeling methods. For negative binomial models, we recommend using a Poisson/gamma mixture or a Poisson/log-normal mixture rather than the built-in negative binomial function. Incomplete-Detection Zero-Inflated Poisson Abundance Model # Written for 100 sites, with 3 collections per site. Covariates are “pred1n” and “pred2n.” { for (i in 1:100) { #specifies 100 sites; can be variable for (j in 1:3) { #specifies 3 collections; can be variable s[i,j] ~ dbin(p[z1[i]],k[i]) } z1[i] <- Pres[i]+1 k[i] <- Pres[i]*K[i] Pres[i] ~ dbern(Psi1[i]) # the following line is a workaround to prevent errors Psi1[i] <- min(0.999999,max(.000001,Psi[i])) K[i] ~ dpois(lambda[i]) log(lambda[i]) <- a[1] + a[2]*pred1n[i] logit(Psi[i]) <- b[1] + b[2]*pred2n[i] } for (n in 1:2) { a[n] ~ dnorm(0.0,0.001) b[n] ~ dnorm(0.0,0.001) } p[1] <- 0 # see note below p[2] ~ dbeta(1,1) # detection constant; can be altered to take covariates } INITS list(a=c(0,0),b=c(0,0),p=c(NA,.5), K=c(10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10),Pres=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)) SIMULATED DATA # sites=100,collections=3,detectability=0.3,mean abundance=10,psi=0.5 list(s=structure(.Data=c(1,2,2,0,0,0,2,3,1,0,0,0,0,0,0,2,2,5,4,3,3,0,0,0,0,0,0,0,0,0,1,2,0,3,5,5,0,0,0,3,4,4,3,4,5,0,1,1,3,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,4,1,3,2,4,2,2,3,0,0,0,0,0,0,0,0,0,3,2,6,0,0,0,0,0,0,0,0,0,3,4,1,1,3,1,8,3,5,0,0,0,5,4,2,0,0,0,2,4,4,0,0,0,2,5,5,1,2,2,3,6,4,0,1,0,2,2,3,0,0,0,2,3,2,0,0,0,0,0,0,1,5,4,4,1,8,3,0,3,3,4,5,0,0,1,2,1,0,1,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,4,4,5,2,2,5,1,6,7,4,0,0,0,0,0,0,0,0,0,0,0,0,6,4,8,0,0,0,5,4,4,2,3,2,2,2,2,2,4,3,3,1,2,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,3,4,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,8,5,7,4,8,0,0,0,4,4,1,4,7,4,0,2,1,0,0,0),.Dim=c(100,3)),pred1n=c(-0.9808, -0.8788, -0.1326, -0.8087, -1.4828, -0.592, -0.3966, -0.0848, -1.6966, 1.4745, -1.3189, 1.4873, -1.32, -0.9385, -0.3362, -0.7619, 0.5491, 0.2913, -0.9361, 1.1749, -1.7581, 0.2986, 0.0625, 0.6589, -0.8249, 0.6441, 0.5863, -1.067, 1.1874, 0.6347, 0.8672, -0.7738, -1.263, 0.2185, 0.3455, -0.3116, 1.0649, 0.7558, -0.4342, -0.3132, 0.217, 0.5406, -0.3927, -0.1887, -1.0399, -1.5462, 1.5988, -1.2821, -0.9623, 1.4327, 0.732, 1.0232, 1.549, 1.2695, -1.7579, -1.4719, -0.538, 0.4308, -0.7835, -1.2664, -1.6242, -1.1987, 0.8928, -0.3226, 1.3402, 1.1371, 1.4078, -1.0667, -0.7533, 0.681, 1.486, 0.907, 0.4803, -0.6974, -0.2451, -0.6505, -0.4931, -0.9849, 0.4452, 0.2391, 1.379, 1.2585, 0.9707, 0.7643, 1.1481, 1.6152, 0.4489, -1.642, -0.2579, 1.2508, -0.0357, -0.5673, 0.5713, 1.5936, 1.5483, -0.9403, 1.1982, -0.1895, -0.2952, -1.2533), pred2n=c(0.9363, -0.2277, 0.7488, -0.1238, -0.759, 1.3078, 1.3984, -0.7596, -1.2972, -1.1435, 0.9521, 0.2484, -0.4283, -0.3621, 0.5859, 1.3969, 1.2519, -0.8954, -1.5461, -1.186, 0.1488, -1.0185, -1.337, 0.6301, 1.5797, -0.0929, -1.2833, -0.9695, -0.8522, 1.146, -0.6858, 0.2233, -1.3318, 0.3218, 0.505, 0.5811, -0.3752, 1.7226, -0.8964, 1.4105, 0.2809, 1.8151, 1.1975, 0.6315, 1.4386, 1.5367, -1.4954, 0.3246, -0.7967, -1.1339, 0.4182, 1.7815, 1.0088, 0.0873, 1.1101, 1.4506, 0.303, -0.601, -0.9258, -0.4829, -1.0119, -0.0398, 1.1198, 1.0286, 1.6802, 0.3045, -0.9735, -1.0594, -0.1734, -1.3458, 0.3306, -0.5014, -0.2568, 0.3692, 0.7235, 1.5909, 0.0783, 0.3098, -0.195, -1.0548, 0.2469, -1.4883, -1.0141, 1.2846, -1.4698, 0.0831, -1.4289, 1.4584, -1.3405, -0.6192, -1.3012, -0.444, -1.4456, 0.8625, 1.1024, -1.1031, -0.0525, -0.8241, 0.1694, -1.0729)) ## End of WinBUGS Code Note: The above version is written to constrain detection such that p=0 if abundance=0. A slightly simpler alternative version of the code, which produces nearly identical results under most circumstances, is given below. This allows estimation of p even when abundance=0. However, we believe the first version is generally preferable. Simplified Incomplete-Detection Zero-Inflated Poisson Abundance Model { for (i in 1:100) { for (j in 1:3) { s[i,j] ~ dbin(p,k[i]) } k[i] <- Pres[i]*K[i] Pres[i] ~ dbern(Psi1[i]) Psi1[i] <- min(0.999999,max(.000001,Psi[i])) K[i] ~ dpois(lambda[i]) log(lambda[i]) <- a[1] + a[2]*pred1n[i] logit(Psi[i]) <- b[1] + b[2]*pred2n[i] } p ~ dbeta(1,1) for (n in 1:2) { a[n] ~ dnorm(0.0,0.001) b[n] ~ dnorm(0.0,0.001) } } INITS list(a=c(0,0),b=c(0,0),p=c(NA,.5), K=c(10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10),Pres=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)) ## End of WinBUGS Code. Data are the same as for previous version. Reference Spiegelhalter, D. J., A. Thomas, N. G. Best, and D. Lunn. 2003. WinBUGS Version 1.4 User Manual. MRC Biostatistics Unit, Cambridge, UK.