Hello,
I am attempting to include a random effect which includes NAs in my N-mixture model. I would like to use mean imputation to deal with the missing data. My problem is that my random variable is multidimensional, and I am struggling with how to tell JAGS to subset my data.
For context, I am modeling avian point counts, where we visited each site three times in a given year. Each visit, a different observer visited the site. I would like to model the random effect of observer, but I would like a different output for each of the 3 visits.
Here is my model. The text in blue represents the code to define the random effect of observer. Attached is an image of the head of the data used in this model.
model {
for(i in 1:n_obs){
alpha3[i] ~ dnorm(0, sigma.o)
}
for( i in 1:M)
{
N[i] ~ dpois(lambda[i])
log(lambda[i]) <- alpha0 + beta1*elev[i] #State model
for (j in 1:J) {
C[i,j] ~ dbin(p[i,j], N[i])
logit(p[i,j]) <- beta0 + alpha3[obs_num[i,j]] #Observation model
}
for (i in 1:n_obs){
obs_num[i,1] ~ dnorm(0, 0.001) #Attempting to subset obs_num
}
for (i in 1:n_obs){
obs_num[i,2] ~ dnorm(0, 0.001)
}
for (i in 1:n_obs){
obs_num[i,3] ~ dnorm(0, 0.001)
}
}
beta0 ~ dnorm(0,1)
alpha0 ~ dnorm(0,1)
beta1 ~ dnorm(0,1)
sigma.o ~ dunif(0,1)
}
Additionally, I have tried:
model {
for(i in 1:n_obs){
alpha3[i] ~ dnorm(0, sigma.o)
}
for( i in 1:M)
{
N[i] ~ dpois(lambda[i])
log(lambda[i]) <- alpha0 + beta1*elev[i] #State model
for (j in 1:J) {
C[i,j] ~ dbin(p[i,j], N[i])
logit(p[i,j]) <- beta0 + alpha3[obs_num[i,j]] #Observation model
}
for (i in 1:n_obs){
for (j in 1:3){
obs_num[i,j] ~ dnorm(0, 0.001) #a different attempt to subset
}
}
}
beta0 ~ dnorm(0,1)
alpha0 ~ dnorm(0,1)
beta1 ~ dnorm(0,1)
sigma.o ~ dunif(0,1)
}
When I run either of these models in R using jagsUI, I get the error "Compilation error; Attempt to redefine node obs_num."
The model has run fine without the addition of this random effect. Any advice about sub-setting the data within the model structure would be greatly appreciated, and I would be happy to provide more information/code! Apologies if I have not included pertinent information, this is my first time posting.
Thanks,
Martha