简体   繁体   中英

R - JAGS - Runtime Error

I'm trying to run his model code with JAGS:

model{
  ## priors
  b0 ~ dnorm(0, 5)
  b1 ~ dnorm(0, 5)
  b2 ~ dnorm(0, 5)
  b3 ~ dnorm(0, 5)
  b4 ~ dnorm(0, 5)
  b5 ~ dnorm(0, 5)
  b6 ~ dnorm(0, 5)
  sigmayear ~ dt(0, 1, 2) I(0, )
  ## likelihood
  for(i in 1:nind){
    for(t in 2:last[i]){
      y[i,t] ~ dbern(prop[i, t - 1])
      prop[i, t - 1] <- y[i, t - 1] * (1 - d[i, t - 1])
      logit(d[i, t - 1]) <- 
        b0 + b1 * temp[i, t] + b2 * sex[i] + b3 * day[t] + 
        b4 * strat[i] + b5 * temp[i, t] * sex[i] + 
        b6 * temp[i, t] * strat[i] + sigmayear * ryear[years[i]]
    } # close t
  } # close i
  for(k in 1:nyears){
    ryear[k] ~ dnorm(0, 1)
  } #close k
}

The data-matrix I created should be fine:

> str(bugs.data)
List of 9
 $ y     : num [1:124, 1:203] 1 1 1 1 1 1 1 1 1 1 ...
 $ nind  : int 124
 $ last  : num [1:124] 98 98 78 91 78 98 87 88 98 111 ...
 $ temp  : num [1:124, 1:203] 1.33 1.33 1.33 1.33 1.33 ...
 $ sex   : num [1:124] 1 0 1 1 1 0 0 0 0 1 ...
 $ day   : num [1:203] -1.72 -1.7 -1.69 -1.67 -1.65 ...
 $ strat : num [1:124] 0 0 0 0 0 0 0 0 0 0 ...
 $ years : num [1:124] 7 7 7 7 7 7 7 7 7 1 ...
 $ nyears: int 8

The actual call with these parameters has been working before...

ni <- 5000 #number of sims
nt <- 1 #get rid of
nb <- 2000 #warm in
nc <- 3 # number of chains

But for some reason, when i want to call it this happens:

> ms <- jags(bugs.data, inits, parameters, "knownfateSurvivalfat.txt", n.chains = nc, n.thin = nt, n.iter = ni, n.burnin = nb, working.directory = getwd())
Compiling model graph
   Resolving undeclared variables
Deleting model

Fehler in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  RUNTIME ERROR:
Compilation error on line 14.
Index out of range taking subset of  y

Somebody has any ideas why "y" should be out of range?

"i" should always go from 1 to 124 which fits to the matrix(bugs.data) and "t" goes from 2 to 203 which is also fine....

Make sure in your data list, it looks like list("y"=y,...) and not list(y="y"...) .

Just a hunch.

Matt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM