5

Wondering if any of you know why JAGS would tell me there was a dimension mismatch with my initial values here.

I am attempting to fit a spatially explicit capture-recapture model in which I estimate a fish location (x,y) at each time step. There are M=64 individuals for T=21 time steps. This is estimated in array s, which loops though i=M and t=T drawing from two normal distributions for each coordinate--x,y. Making the dimension of s = (64,2,21).

My initial values for this array are plausible locations within suitable habitat, and is an array with dimensions 64, 2, 21.

Yet, JAGS gives me the error, Error in setParameters(init.values[[i]], i) : RUNTIME ERROR: Dimension mismatch in values supplied for s. If I simply dont initialize it, I get the same error but for a state matrix, z, with dimensions 64,21. If I also dont supply values for z, I get the error Error in node y[1,1,2] Node inconsistent with parents, where y is my array of observations, dimensions 64, 7, 21 (the second element is the #of detection gates).

Any help is very appreciated. See below for full code.

Cross-posted at SourceForge, with the initial values for s attached. Not quite sure how to post it here.

sink("mod.txt")
cat("
model{


#######################################
# lamda0 = baseline detection rate, gate dependent and stage dependent
# sigma2 = scale parameter for decline in detection prob, time dependent
# phi =  survival, stage dependent
# s = activity center
# M=64 individuals, T=21 time steps
# z = true state, alive (1) or dead (0)
#######################################


for(i in 1:M){
for (j in 1:ngates){
  logit(lamda0[i,j])<- beta[group[i]]+ gamma[j]
}
}

for(j in 1:ngates){
  gamma[j] ~ dnorm(0,0.001)
  lam0.g1[j]<- 1/(1+exp(-gamma[j]))
  lam0.g2[j]<- 1/(1+exp(-gamma[j]-beta[2]))
}

beta[1]<-0
beta[2] ~dnorm(0,0.001)T(-10,10)

for (t in 1:T){
  sigma2[t] ~ dgamma(0.1,0.1)

}


tauv ~ dunif(0,40)
tau<- 1/(tauv*tauv)


phi[1] ~dunif(0,1)
phi[2] ~dunif(0,1)



for(i in 1:M){
  for(t in 1:(first[i]-1)){
    s[i,1,t]<-0   #before first detection, not in system
    s[i,2,t]<-0   #before first detection, not in system

    z[i,t]<-0         
  }
  for(t in (last[i]+1):T){
    s[i,1,t]<-0 
    s[i,2,t]<-0 
    z[i,t]<-0
  }
  #First period, locs and states
    z[i,first[i]] ~ dbern(1)   #know fish is alive 
    s[i,1,first[i]] ~ dunif(xl,xu)    #possible x,y coords 
    s[i,2,first[i]] ~ dunif(yl,yu)


    xdex[i,first[i]]<- trunc(s[i,1,first[i]]+1)
    ydex[i,first[i]]<- trunc(s[i,2,first[i]]+1)
    pOK[i,first[i]] <- habmat[xdex[i,first[i]],ydex[i,first[i]]] # habitat check
    OK[i,first[i]] ~ dbern(pOK[i,first[i]])   # OK[i] = 1, the ones trick


  for(j in 1:ngates){
  #First period, detection
    d[i,j,first[i]]<-sqrt(pow((s[i,1,first[i]]-gate.locs[j,1]),2) + pow((s[i,2,first[i]]-gate.locs[j,2]),2)) #estimate distance to gate (euclid) 
    d2[i,j,first[i]]<-pow(d[i,j,first[i]],2)
    lam_g[i,j,first[i]]<-lamda0[i,j]*exp(-d2[i,j,first[i]]/(2*sigma2[first[i]]))    
    y[i,j,first[i]] ~ dpois(lam_g[i,j,first[i]])  # number of captures/period/gate
}


  #Subsequent periods
  for(t in (first[i]+1):last[i]){
    s[i,1,t] ~ dnorm(s[i,1,(t-1)],tau)T(xl, xu)
    s[i,2,t] ~ dnorm(s[i,2,(t-1)],tau)T(yl, yu)


    xdex[i,t]<- trunc(s[i,1,t]+1)
    ydex[i,t]<- trunc(s[i,2,t]+1)
    pOK[i,t] <- habmat[xdex[i,t],ydex[i,t]] # habitat check
    OK[i,t] ~ dbern(pOK[i,t])   # OK[i] = 1, the ones trick

    for(j in 1:ngates){
        d[i,j,t]<-sqrt(pow((s[i,1,t]-gate.locs[j,1]),2) + pow((s[i,2,t]-gate.locs[j,2]),2)) #estimate distance to gate (euclid) 
        d2[i,j,t]<-pow(d[i,j,t],2)
        lam_g[i,j,t]<-lamda0[i,j]*exp(-d2[i,j,t]/(2*sigma2[t]))
        y[i,j,t] ~ dpois(lam_g[i,j,t])
    }  

    phiUP[i,t]<-z[i,t-1]*phi[group[i]]  #estimate 3-day survival rate
    z[i,t] ~ dbern(phiUP[i,t])


  }




} 
}#model
    ", fill=TRUE)
sink()

OK = matrix(1, nrow=M, ncol=T)

dat<-list(y=y, first=first, habmat=habmat, group=group, 
          xl=xl,xu=xu,yl=yl,yu=yu,
          last=last, OK = OK, M=M, T=T, 
          ngates=ngates,gate.locs=gate.locs)

z<-matrix(NA,M,T)
  for(i in 1:M){
    for(t in first[i]:last[i]){
      z[i,t]<-1
    }
  }

s<-readRDS("s_inits.Rda")





inits<-function() {list(phi=runif(2,0,1), sigma2=runif(T,0,0.5), tauv=runif(1,0,30), s=s, z=z)}

init1<-inits()
init2<-inits()
init3<-inits()
jag.inits<-list(init1,init2,init3)

params<-c("phiUP","tauv","sigma2","s","z","beta","gamma","phi")
  • What are the dimensions (i.e., `dim(s)`) of `s_inits.Rda`, the value of object `M`, `first`, `last`, and `T`? – mfidino Feb 27 '19 at 14:38
  • Hi, the dimensions of s_inits are 64,2, 21; lengths of M, first, last, and T are 64, 64, 64, and 21, respectively. – Janelle Badger Feb 27 '19 at 19:41
  • I'm guessing it has to do with your vectors `first` and `last`, but without a reproducible example it's very difficult to pin point the cause of this error. – mfidino Mar 01 '19 at 14:43
  • I have the exact same problem and can't figure it out – Gmichael Apr 21 '21 at 11:51
  • tbh, at some point there is no such thing as a "reproducible example" and insisting on one just to provide a simple fix only trivializes a problem potentially specific to the data... – Gmichael Apr 21 '21 at 12:36

0 Answers0