I am not even sure how to phrase what I am doing so this may have been asked and answered and I just don't know how to search for it efficiently. I have written a hierarchical model with 4 levels of hierarchy: population<-individual animal<-individual year for that animal<-seasons within that year. As would be expected, some animals are only recorded in a single year and/or don't have records from every season within a year.
The for loops to generate the priors are all written with indicator variables to generate a "ragged" output that only generates a prior if that animal existed that year and season. I use $getNodeNames and $getParents to define my monitors and it correctly identifies the data shape.
However, when I get the posteriors, everything has been squared off and I have posteriors that are all zero filling in what would be the holes in matrices and arrays (I did have to define my initial values with these "ghost values" because I am unaware of a way to define my inital values with uneven structure).
The outputs and estimates of the hyperparameters seem reasonable given my knowledge of the system being modeled and a subjective look at the different levels of the hierarchy feeding into each other. I have two questions. The first and most important is, do these values somehow skew my estimates? And second, how do I prevent them from being extracted? They are not included in my monitors and balloon my output, and provide no value to interpretation.
John
Below is my nimble code, I am currently very early in forming this model and focusing on hierarchy structure.
simpleModel <- nimbleCode( {
mu.R.Individual.I~dnorm(0, sd=2)
mu.B.Forest.dens~ddexp(0, 1)
mu.B.Dev.dist~ddexp(0,1)
mu.B.Dist_Maj_Road~ddexp(0,1)
for(i in 1:n.bears){
R.Individual.I[i]~dnorm(mu.R.Individual.I, sd=2)
B.Forest.dens[i]~ddexp(mu.B.Forest.dens, 1)
B.Dev.dist[i]~ddexp(mu.B.Dev.dist,1)
B.Dist_Maj_Road[i]~ddexp(mu.B.Dist_Maj_Road,1)
for(j in 1:bear.year.index[i]){
R.Individual.I.y[i,j]~dnorm(R.Individual.I[i], sd=2)
B.Forest.dens.y[i,j]~ddexp(B.Forest.dens[i], 1)
B.Dev.dist.y[i,j]~ddexp(B.Dev.dist[i],1)
B.Dist_Maj_Road.y[i,j]~ddexp(B.Dist_Maj_Road[i],1)
for(k in 1:3){
R.Individual.I.y.s[i,j,k]~dnorm(R.Individual.I.y[i,j], sd=2)
B.Forest.dens.y.s[i,j,k]~ddexp(B.Forest.dens.y[i,j], 1)
B.Dev.dist.y.s[i,j,k]~ddexp(B.Dev.dist.y[i,j],1)
B.Dist_Maj_Road.y.s[i,j,k]~ddexp(B.Dist_Maj_Road.y[i,j],1)
}
}
}
# Likelihood
for(i in 1:N){
used[i]~dbern(s[i])
logit(s[i])<-R.Individual.I.y.s[bear.number[i],bear.year[i], season[i]]+
B.Forest.dens.y.s[bear.number[i],bear.year[i], season[i]]*Forest.dens[i]+
B.Dev.dist.y.s[bear.number[i],bear.year[i], season[i]]*Dev.dist[i]+
B.Dist_Maj_Road.y.s[bear.number[i],bear.year[i], season[i]]*Dist_Maj_Road[i]
}
})