Error: Dynamic index out of bounds

64 views
Skip to first unread message

Alex Lu

unread,
Jan 10, 2023, 9:37:10 PM1/10/23
to nimble...@googlegroups.com
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)
})



Chris Paciorek

unread,
Jan 11, 2023, 11:12:29 AM1/11/23
to Alex Lu, nimble...@googlegroups.com
Hi Alex,

I assume that J=3, since you're indexing betaw and betab with an index that must be in {1,2,3}. 
The warning indicates that at least one value in the Zw vector is not in {1,2,3}. It's probably a question
of how you are initializing the values of Zw.

-chris

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/CADjkiwu_YZTJ%3DgVJUFhAnHnng4bU_F4%3DVhQ3g3WJHBq6B6umeQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages