0

I'm completely new to JAGS/OpenBUGS so I would really appreciate a push in the right direction when it comes to specifying my model. I'm using an unbalanced longitudinal data that is compiled by 103 countries over 15 years where 12 years is picked in this case. The DV is the Gini coefficient, which shouldn't be modeled log-Normal but maybe rather Beta, although right now the focus is on just understanding how to compile the model in JAGS. I'm using a fixed effect model for the time being.

The data and code I'm running:

> head(x)
          Year     II2       II3       II4     ..... II24
1          1       2.956233  40.90458 4.475183       16.443553
8          1       1.257794  85.47378 2.395186       19.333433
19         1       4.139706 141.07899 2.544640       25.555404
37         1       2.233664  98.51313 3.902835       42.533333
49         1       2.879734  61.39000 1.471334       18.884444
71         1       3.381762  60.23783 3.432614       16.334222


> head(y)
        Year       II1
1         1     0.3240000
8         1     0.2576667
19        1     0.3132500
37        1     0.2700000
49        1     0.2744286
71        1     0.3250000

dim(x)
1224   23

length(y)
1224  

Time <- 12, N <- length(y$II1)#No. of Obs.

dat <- list(x=x, y=y, N=N, Time=Time, p=dim(x)[2]), 
inits <- funtion(){list(tau.1=1, tau.2=1, eta=1, alpha=0, beta1=0, beta2=0, beta3=0)}

model6 <- "model{
for(i in 1:N){for(t in 1:Time){
y[i,t]~dlnorm(mu[i,t],tau.1)
mu[i,t] <- inprod(x[i,t],beta[])+alpha[i]}
alpha[i]~dnorm(eta, tau.2)}

for (j in 1:p) {
b[j]~dnorm(0,0.001)
}

eta~dnorm(0, 0.0001)
tau.2~dgamma(0.01,0.01)
tau.1~dgamma(0.01,0.01)


 }"

reg.jags <- jags.model(textConnection(model), data=dat, inits=inits, n.chains=1, n.adapt=1000)

And I keep getting this runtime error:

Error in jags.model(textConnection(model), data = dat, inits =   inits,  : 
RUNTIME ERROR:
Compilation error on line 3.
Index out of range taking subset of  y

Any suggestions on what I should do differently would be hugely appreciated! I know there are 3 "tricks" you can apply to unbalanced data but I'm still a little bit confused about how all of this works, e.i. how JAGS read the data input.

Cheers

J

2
  • i don't see a yy anywhere in your model. Are you sure this is the correct code and error message? Also, I see an xx in your model, but you don't pass a variable named xx to jags in your data block, you pass it a variable named x. Aug 12, 2016 at 17:42
  • @JacobSocolar: Ive edited the code a bit as I made som changes. I dont know if the changes were sensible, but at least I think the code is more clean cut and without typos. I still get the same compilation error though.
    – Herzriesig
    Aug 12, 2016 at 19:53

1 Answer 1

0

Your dataframe y only has 2 columns. But Time is 12. Where you have

y[i,t]~dlnorm(mu[i,t],tau.1)

inside a loop

for(t in 1:Time){

think about what happens when t goes up to 3 (on its way to Time=12).

You are asking JAGS to look at y[i,3], which doesn't exist. Hence "Index out of range".

3
  • Thanks for the comment @Jacob. I figured it had to with that, however I don't know exactly in what format I should have my data in. What do you reckon I should do?
    – Herzriesig
    Aug 14, 2016 at 11:16
  • I'm assuming that in your data.frame y, y$Year takes integer values from 1 to 12. You need: y[i,t]~dlnorm(mu[i],tau.1); mu[i] <- inprod(x[i,y[1,i]],beta[])+alpha[i]} Note that you will still get a different mu for every observation i, which is what you want. Aug 16, 2016 at 2:46
  • Thank you so much for your comments @Jacob. I used your logic and made it run in the end. However Im not sure if it is correctly specified, Ill post the script of the beta regression when Im done with it.
    – Herzriesig
    Aug 17, 2016 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.