1

I am trying to solve multivariate regression with multiple dependent variables on Winbugs. But I am getting errors during compilations. I tried to solve based on solutions to the same problem but was unsuccessful. Any help will be highly appreciated.

model {
for(i in 1:n) 
{ for(k in 1:J)
 {                  y[i,k]~ dpois(mu[i,])
                    log(mu[i,1]) <- beta1[1]*x1[i] + beta2[1]*x2[i] + b[,1]
                    log(mu[i,2]) <- beta1[2]*x1[i] + beta2[2]*x2[i] + b[,2]
       }}    

#  PRIORS
     for (i in 1:n) { 
      for(k in 1:J)  {
      b[i,k] <- 1
              }} 
# Scale Matrix
     for(i in 1:J)
     {
     for (j in 1:J) 
      {  
       R[i,j] <- equals(i,j)
      }}
    for (j in 1:J) {beta1[j]~ dmnorm(zero[], B[,])
       beta2[j]~ dmnorm(zero[], B[,]) }
    for(i in 1:J)
     { 
         for (j in 1:J) 
       {  B[i,j] <- 0.01*equals(i,j)
      }}
    for (i in 1:J) { zero[i] <- 0}
    }


#DATA 
list(n=3, J=2)


#DATA
y[ ,1]  x1[]    x2[]    y[,2]   
   0       9.91     8.34     1               
  3    10.48    10.14    79          
 0     10.31    9.42     40

1 Answers1

0

The error is because you have mu nested within two for loops. Therefore, you are filling row i J times which is not possible. What you have is:

for(i in 1:n){
for(k in 1:J){
             y[i,k]~ dpois(mu[i,])
                log(mu[i,1]) <- beta1[1]*x1[i] + beta2[1]*x2[i] + b[,1]
                log(mu[i,2]) <- beta1[2]*x1[i] + beta2[2]*x2[i] + b[,2]
   }}

What it looks like it should be is:

for(i in 1:n){
                log(mu[i,1]) <- beta1[1]*x1[i] + beta2[1]*x2[i] + b[,1]
                log(mu[i,2]) <- beta1[2]*x1[i] + beta2[2]*x2[i] + b[,2]
for(k in 1:J){
             y[i,k]~ dpois(mu[i,])

   }}

This way you are not supplying multiple definitions to each cell in mu

mfidino
  • 3,030
  • 1
  • 9
  • 13
  • thanks a lot friend. Kindly tell if you have solution for the new error that is coming ie " vector valued logical expression must have more than one component ". – Prabhat Kumar Nov 12 '16 at 03:02
  • I can only assume that is related to what you are putting in one of the multivariate normal distributions. For example, you are trying to put a bunch of values into one cell here `beta2[j]~ dmnorm(zero[], B[,])` – mfidino Nov 14 '16 at 14:44
  • Thanks for the suggestion. Is there any way of assigning each beta1[j] or beta2[j] a particular element of the normal distributed matrix. I tried by defining beta1[1] <- beta3[1,1] , where the matrix beta3 is obtained as beta3[j,j] <- dmnorm(zero[],B[,]). But same error as before is coming. – Prabhat Kumar Nov 15 '16 at 06:12
  • if `beta1` is `j` long just take it out of the for loop. `beta1[]~ dmnorm(zero[], B[,])` – mfidino Nov 15 '16 at 14:40
  • But this leads to error at the time of model check, somewhat like - "Empty slot not allowed in variable name" – Prabhat Kumar Nov 15 '16 at 15:11