################################################################ # Blackbirds case study # O. Gimenez, S. Cubaynes # January 2011 ################################################################ model { #----- level 1: likelihood for CR data for (i in 1:N) # for each individual { # '1' means it is alive the first time it was seen alive[i, First[i]] ~ dbern(1) # for each year after the first for (j in (First[i]+1):Years) { # state equation alivep[i,j] <- phi[i] * alive[i, j-1] alive[i,j] ~ dbern(alivep[i,j]) # observation equation sightp[i,j] <- p * alive[i, j] dat[i, j] ~ dbern(sightp[i,j]) } } #----- level 2: SEM specification on survival for (i in 1:N){ # measurement model mu1[i] <- ksi[i] x[i,1] ~ dnorm(mu1[i],tau[1]) mu2[i] <- theta[1] * ksi[i] x[i,2] ~ dnorm(mu2[i],tau[1]) mu3[i] <- theta[2] * ksi[i] x[i,3] ~ dnorm(mu3[i],tau[2]) mu4[i] <- theta[3] * ksi[i] x[i,4] ~ dnorm(mu4[i],tau[2]) phi[i] <- 1/(1+exp(-eta[i])) # (quadratic) structural model eta[i] <- gamma[1] * ksi[i] + gamma[2] * pow(ksi[i],2) + zeta[i] ksi[i] ~ dnorm(0, tau[3]) zeta[i] ~ dnorm(0,1) } #----- priors # for the factor loadings theta[1] ~ dnorm(0,0.01) theta[2] ~ dnorm(0,0.01) theta[3] ~ dnorm(0,0.01) gamma[1] ~ dnorm(0,0.01) gamma[2] ~ dnorm(0,0.01) # for the SD of the random effects sig[1] ~ dunif(0,100) tau[1] <- 1/(sig[1]*sig[1]) sig[2] ~ dunif(0,100) tau[2] <- 1/(sig[2]*sig[2]) sig[3] ~ dunif(0,100) tau[3] <- 1/(sig[3]*sig[3]) # for the detection probability p ~ dunif(0,1) } ################################################################ # Blue tits case study # S. Cubaynes, O. Gimenez # January 2011 ################################################################ model { #----- level 1: likelihood for CR data for (i in 1:N) # for each individual { # '1' means it is alive the first time it was seen alive[i, First[i]] ~ dbern(1) # for each year after the first for (j in (First[i]+1):Years) { # state equation alivep[i,j] <- phi[j-1] * alive[i, j-1] alive[i,j] ~ dbern(alivep[i,j]) # observation equation sightp[i,j] <- p[j-1] * alive[i, j] dat[i, j] ~ dbern(sightp[i,j]) } } #----- level 2: SEM specification on survival for(j in 1:Years) { #-- measurement model # clutch size mu1[j] <- lambda[1] * repro[j] y[j,1] ~ dnorm(mu1[j],taueps[1]) # chicks weight mu2[j] <- lambda[2] * repro[j] y[j,2] ~ dnorm(mu2[j],taueps[2]) # chicks survival mu3[j] <- lambda[3] * repro[j] y[j,3] ~ dnorm(mu3[j],taueps[3]) # adults weight mu4[j] <- lambda[4] * inv[j] y[j,4] ~ dnorm(mu4[j],taueps[4]) # survival survival[j] <- lambda[5] * inv[j] + epssurvival[j] epssurvival[j] ~ dnorm(0,1) phi[j] <- 1/(1+exp(-survival[j])) # peak width mu5[j] <- theta[1] * env[j] x[j,1] ~ dnorm(mu5[j],taudelta[1]) # peak mode mu6[j] <- theta[2] * env[j] x[j,2] ~ dnorm(mu6[j],taudelta[2]) #-- structural model inv[j] <- gamma * env[j] + epsinv[j] epsinv[j] ~ dnorm(0,1) repro[j] <- b * inv[j] + epsrepro[j] epsrepro[j] ~ dnorm(0,1) env[j] ~ dnorm(0,1) } #----- priors # for the regression parameters b ~ dnorm(0,0.01) gamma ~ dnorm(0,0.01) for(k in 1:5){lambda[k] ~ dnorm(0,0.01)} for(k in 1:2){theta[k] ~ dnorm(0,0.01)} # for the SD of the random effects for(j in 1:5){ taueps[j] <- 1/(sdeps[j]*sdeps[j]) sdeps[j] ~ dunif(0,100)} for(j in 1:2){ taudelta[j] <- 1/(sddelta[j]*sddelta[j]) sddelta[j] ~ dunif(0,100)} # for the detection probabilities for(j in 1:(Years-1)) {p[j] ~ dunif(0,1)} }