I'm wondering if someone can help me troubleshoot here. I'd like to do a goodness of fit assessment for the poisson log normal model below (this is just the simple test model). When I comment out the fit <- sum(resi[]) and fit.new <- sum(resi.new[]) lines the model runs, but I obviously need those values to do the posterior predictive check.
Any thoughts on why this might not be working? I've included the error message and the model.
Thanks for any guidance you can provide! Michelle
Error in checkForRemoteErrors(val) : 3 nodes produced errors; first error: RUNTIME ERROR: Compilation error on line 28. Dimension mismatch taking subset of resi.new
I should also mention that when I remove the brackets from the fit and fit.new statements, I get a different error:
Error in checkForRemoteErrors(val) : 3 nodes produced errors; first error: RUNTIME ERROR: Compilation error on line 27. Cannot evaluate subset expression for fit.new
Here's the model:
model {
# Priors
for (i in 1:nyear){
alpha[i]~dnorm(0,0.001)
}
beta ~ dnorm(0,0.001)
sigma ~ dunif(0, 10)
tau <- 1 / (sigma * sigma)
# Likelihood
for (i in 1:n*nyear) {
for (j in 1:J){
y[i,j] ~ dpois(lambda[i,j])
log(lambda[i,j]) <- alpha[year[i]] + beta*x[i] + eps[i,j]
eps[i,j] ~ dnorm(0, tau)
resi[i,j] <- pow((y[i,j]-lambda[i,j]),2) / (sqrt(lambda[i,j])+e)
new.y[i,j] ~ dpois(lambda[i,j])
resi.new[i,j] <- pow((new.y[i,j]-lambda[i,j]),2) / (sqrt(lambda[i,j])+e)
}
}
fit <- sum(resi[])
fit.new <- sum(resi.new[])
}
resi.new
and resi
are both i by j matrices. If you are trying to get the posterior of the residuals over all of the data points you could make a temporary vector that you could then sum over. Something like this should work for you at the end of the model (instead of the two lines of code you currently have
for( j in 1:J){
temp.fit[j] <- sum(resi[ ,j])
temp.fit.new[j] <- sum(resi.new[, j])
}
fit <- sum(temp.fit[])
fit.new <- sum(temp.fit.new[])