I have fit this model many times without issue, but went back and added a few data points and now I am getting this error. I have tried removing the 'a0' parameter from the initial values and the error goes away, but then I get NA's in my model results.
There are no NA's in `city_vec` nor `grade_vec` and all objects are of the correct length. Thanks in advance for the help.
norm_mod <- nimbleCode({
# priors for betas
for(grade in 1:ngrade){
b0[grade] ~ dnorm(0, sd = b0_sd)
b1[grade] ~ dnorm(0, sd = b1_sd)
}
# priors for sigma terms
a0_sigma ~ dunif(0.001, 100)
data_sigma ~ dunif(0.001, 100)
# hyper priors for beta sigmas
b0_sd ~ dunif(0.001, 100)
b1_sd ~ dunif(0.001, 100)
# likelihood
for(grade in 1:ngrade){
for(city in 1:ncity){
a0_linpred[grade, city] <-
b0[grade] + b1[grade] * log_pop_dens[city]
a0[grade,city] ~ dnorm(a0_linpred[grade,city], sd = a0_sigma)
}
}
for(n in 1:ndata){
y[n] ~ dnorm(a0[grade_vec[n],city_vec[n]], sd = data_sigma)
}
})
# create model arguments
# constants list
my.constants <- list(ngrade = ngrade,
ncity = ncity,
ndata = ndata,
grade_vec = as.numeric(as.factor(final_dataset$holc_grade)),
city_vec = final_dataset$ID,
log_pop_dens = log_pd_all)
# initial values list
initial.values <- function () list(b0 = rnorm(ngrade, 100),
b1 = rnorm(ngrade, 100),
b0_sd = runif(1,0.001,100),
b1_sd = runif(1,0.001,100),
a0 = matrix(rnorm(ngrade*ncity),
nrow = ngrade,
ncol = ncity),
a0_sigma = runif(1,0.001,100),
data_sigma = runif(1,0.001,100))