Hi Nimble experts,
I have tried to fit a locally smooth model using nimble, however, I got the following error: [Warning] Dynamic index out of bounds: expit(betaw[Zw[i]] + u1[i] + v1[i])
The model that I proposed to do is to capture clusters in geographic regions, where the model includes a constant intercept term (beta) with 3 distinct values (defined by Z), if adjacent units are in different clusters, then they will have different probabilities. I appreciate any suggestions and hints.
Here is the code:
p1=c(0.33,0.33,0.34)
p2=c(0.33,0.33,0.34)
loc.model09<-nimbleCode({
for (i in 1:N){
rw[i]~dbinom(pw[i],tn[i])
logit(pw[i])<-betaw[Zw[i]]+u1[i]+v1[i]
lb[i]~dbinom(pb[i],tn[i])
logit(pb[i])<-betab[Zb[i]]+u2[i]+v2[i]
prow[i]<-exp(betaw[Zw[i]]+u1[i]+v1[i])/(1+exp(betaw[Zw[i]]+u1[i]+v1[i]))
prob[i]<-exp(betab[Zb[i]]+u2[i]+v2[i])/(1+exp(betab[Zb[i]]+u2[i]+v2[i]))
index[i]<-prow[i]-prob[i]
v1[i] ~ dnorm(0, tau = tau.v1)
v2[i] ~ dnorm(0, tau = tau.v2)
Zw[i]~dcat(p1[1:3])
Zb[i]~dcat(p2[1:3])
}
u1[1:N]~dcar_normal(adj[1:L], weights[1:L], num[1:N], tau1, zero_mean = 1)
u2[1:N]~dcar_normal(adj[1:L], weights[1:L], num[1:N], tau2, zero_mean = 1)
#BETA and Z
for (j in 1:J){
betaw[j]~dflat()
betab[j]~dflat()
}
dummy1~dconstraint(betaw[1] < betaw[2] & betaw[2] < betaw[3])
dummy2~dconstraint(betab[1] < betab[2] & betab[2] < betab[3])
tau1~dgamma(0.001,0.001)
sigma2.tau1 <- 1/tau1
tau2~dgamma(0.001,0.001)
sigma2.tau2 <- 1/tau2
tau.v1~dgamma(0.001, 0.001)
tau.v2~dgamma(0.001, 0.001)
})