## Code adapted from Robin Wyatt
model{
##------ SAMPLING MODEL -----------------------
## Population size at surveyed sites
## FIRST TRY ------------
## If I try to do this below, BUGS is unable to set the initial values.
# for(i in 1:num.survey.sites)
# {
# sden[i] <- d[sample.siteids[i]]
# x.n[i] <- sden[i] * lengths[sample.siteids[i]] * widths[sample.siteids[i]]
# n[i, 1] ~ dpois(x.n[i])
#
# for(j in 1:num.survey.site.removals[i] )
# {
# n[i, j + 1] <- n[i, j] - catches.at.survey.site[i, j]
# catches.at.survey.site[i, j] ~ dbin(p[i], n[i, j])
# }
# }
## SECOND TRY ------------
## If I try to do this below, BUGS complains saying that I have used
## an undefined node "nn"
for(i in 1:num.survey.sites)
{
x.n[i] <- d[sample.siteids[i]] * lengths[sample.siteids[i]] * widths[sample.siteids[i]]
n[i] ~ dpois(x.n[i])
}
## After first re-seining
for(i in 1:num.survey.sites)
{
nn[i,2] <- n[i] - catches.at.survey.site[i, 2]
catches.at.survey.site[i, 2] ~ dbin(p[i], n[i])
}
## After all subsequent re-seinings
for(i in 1:num.survey.sites)
{
for(j in 3:num.survey.site.removals[i] )
{
nn[i,j+1] <- nn[i,j] - catches.at.survey.site[i, j]
catches.at.survey.site[i, j] ~ dbin(p[i], nn[i, j])
}
}
##------ DENSITY MODEL ------------------------
## Expected densities and pop sizes at all sites.
for(s in 1:total.sites)
{
u[s] <- mu.d
logden[s] ~ dnorm(u[s], tau.d)
log(d[s]) <- logden[s]
x.ipop[s] <- d[s] * lengths[s] * widths[s]
ipop[s] ~ dpois(x.ipop[s])
}
## Hyperpriors for density
mu.d ~ dnorm(0,1.0E-6)
tau.d ~ dgamma(1.0E-3, 1.0E-3)
sigma.d <- pow(tau.d, -0.5)
##-------CAPTURE PROBABILITY MODEL -----------------------
## Expected capture probability
for(i in 1:num.survey.sites )
{
z[i] <- mu.p
p.prime[i] ~ dnorm(z[i], tau.p)I(-3,3)
logit(p[i]) <- p.prime[i]
}
## Hyperpriors for capture probability
mu.p ~ dnorm(0,1.0E-6)
tau.p ~ dgamma(1.0E-3, 1.0E-3)
sigma.p <- pow(tau.p, -0.5)
## ------- OVERALL SUMMARIES
## Reach and river totals
for(r in 1:num.reaches)
{
for (t in 1:total.sites)
{
temppop[r, t] <- equals(r, reachid[t]) * ipop[t]
}
rpop[r] <- sum(temppop[r, ])
}
tpop <- sum(rpop[])
## Stream order totals
for(i in 1:numorders)
{
for (t in 1:total.sites)
{
temp[i, t] <- equals(i, orders[t]) * ipop[t]
}
opop[i] <- sum(temp[i, ])
}
}
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list