statsmess
statsmess

Reputation: 1

WinBUGS error: vector valued relation z must involve consecutive elements of variable

I am trying to model a multivariate Probit model for my binary data. I have been trying everything but WinBUGS in return gives me this error. Any ideas or suggestion are warmly welcomed.

model{ for (i in 1:ns){ ## loop over studies

for (k in 1:2){   ### loop over arm
  for (j in 1:2){  ###  loop over outcomes

    r[i,k,j] ~ dbin(p[i,k,j],n[i,k,j]);             ## Likelihood Function  
    p[i,k,j] <-  phi(z[i,k,j])
    z[i,k,1:2] ~  dmnorm(theta[i,1:2],with[i,,])I(-5, 5)    #latent variable (z<0) or Probit link       

   theta[i,1] <- alpha[i,k,1] + beta[i,k,1]
   theta[i,2] <- alpha[i,k,2] + beta[i,k,2]
  }   ###Close  loop over outcomes

   }   ###Close  loop over arms

alpha[i,2,1] <- 0   
alpha[i,2,2] <- 0 
alpha[i,1,1:2] ~ dnorm(0,.0001)
beta[i,2,1:2] ~  dmnorm(d[1:2],prec[,])    
beta[i,1,1] <- 0   
beta[i,1,2] <- 0 


## priors on within study cov matrix
with[i,1:2,1:2] <- inverse(cov.mat[i,1:2,1:2])   


  #define elements of within-study covariance matrix
  cov.mat[i,1,1] <-  1
  cov.mat[i,2,2] <-  1
  ### prior from IPD data  ######
  cov.mat[i,1,2] ~   dbeta(a[i],b[i])
  cov.mat[i,2,1] <-  cov.mat[i,1,2] 
  a[i]<-31.97
  b[i]<- 4.52                   

}#### Close loop over studies       

for (i in 1:2) {
  d[i]  ~ dnorm(0.0000E+00, 0.0001)    # overall treatment effects
}
## priors on between study cov matrix
prec[1:2,1:2]<-inverse(tau[1:2,1:2])
pi<-3.14/2
a1~dunif(0, pi)
rho.tau<-cos(a1)
sd[1]~dunif(0,2)
sd[2]~dunif(0,2)
tau[1,1]<-pow(sd[1],2)
tau[2,2]<-pow(sd[2],2)
tau[2,1]<-tau[1,2]
tau[1,2]<-sd[1]*sd[2]*rho.tau
}        #END MODEL

These are my data:

list(ns=2)
t[,1,1] t[,1,2] t[,2,1] t[,2,2]  r[,1,1]  n[,1,1] r[,2,1] n[,2,1] r[,1,2]     n[,1,2] r[,2,2] n[,2,2]
1   0   1   0   19  77  23  77  60  82  70  82
1   0   1   0   27  199 54  199 231 393 318 393
END

The model is syntactically correct and it allows me to load the data. Once I compile I get the error in the title. Thank you for any help given

Upvotes: 0

Views: 465

Answers (2)

Tristan
Tristan

Reputation: 1

I had the same error when using dmulti, i.e. with the error 'vector-valued relation r must involve consecutive elements of variable'.

Following the suggestion here: https://www.jiscmail.ac.uk/cgi-bin/wa-jisc.exe?A2=BUGS;41045666.1110, I reverted my indices indexing my response variable 'r' (and therefore also transposed the matrix response variable input data). I applied the same indices reversion and transpose of the denominator 'n'.

This worked:

r[i,1:4] ~ dmulti(pi[1:4], n[i,1:4])

whereas this did not:

r[1:4, i] ~ dmulti(pi[1:4], n[1:4, i])

Upvotes: 0

mfidino
mfidino

Reputation: 3055

It looks as if you are inputting a 2 by 2 matrix into the mean of the multivariate normal distribution right here.

z[i,1:2,k] ~  dmnorm(theta[i,,],with[i,,])I(-5, 5)    #latent variable (z<0) or Probit link

However, it appears as if z is only a vector of length 2. You need to input a vector into the mean of dmnorm and give it an associated variance covariance matrix (i.e. if you supply a vector of length 3, it needs to have a 3 by 3 variance covariance matrix). Right now you have a 2 by 2 matrix input into the mean (4 parameters) and a 2 by 2 variance covariance matrix. As I do not really know the motivation behind the model I can't really provide any suggestions on how to fix it per se, but it seems to me that you need to index theta a bit more in order to prevent putting a matrix into dmnorm.

Upvotes: 0

Related Questions