Pergunta

I am having a very hard time trying to subtract two vectors in my OpenBUGS model. The last line of the code below keeps giving the error "expected right parenthesis error":

model { 
  for ( i in 1:N) {
    for(j in 1:q) {
      vv[i,j] ~ dnorm(vz[i,j],tau.eta[j])
    }
    vz[i,1:q] ~ dmnorm(media.z[i,], K.delta[,])
    for(j in 1:q) {
      mean.z[i,j] <- inprod(K[i,] , vbeta[j,])
    }
    K[i,1] <- 1.0
    for(j in 1:N) {
      K[i,j+1] <- sum(ve[,i] - ve[,j])
    }
  }

If I change that line to K[i,j+1] <- sum(ve[,i]) - sum(ve[,j]), then the model works fine, but that is not what I want to do. I would like to subtract element-wise.

I searched SO for OpenBUGS, but there are only a few unrelated topics:

OpenBUGS - Variable is not defined

OpenBUGS: missing value in Bernoulli distribution

In Stats Stack Exchange there is this post which is close, but I still could not make how to implement this in my model:

https://stats.stackexchange.com/questions/20653/vector-multiplication-in-bugs-and-jags/20739#20739

I understand I have to write a for loop, but this thing is sure giving me a big headache. :)

I tried changing that line to:

for(k in 1:p) { temp [k] <- ve[k,i] - ve[k,j] }
K[i,j+1] <- sum(temp[])

where 'p' is the number of rows in each 've'. Now I keep getting the error "multiple definitions of node temp[1]".

I could definitely use some help. It will be much appreciated.

Best regards to all and thanks in advance!

PS: I wanted to add the tag "OpenBUGS" to this question but unfortunately I couldn't because it would be a new tag and I do not have enough reputation. I added "winbugs" instead.

Foi útil?

Solução

The "multiple definitions" error is because temp[k] is redefined over and over again within a loop over i and another loop over j - you can only define it once. To get around that, use i and j subscripts like

for(k in 1:p) { temp[k,i,j] <- ve[k,i] - ve[k,j] } 
K[i,j+1] <- sum(temp[,i,j])

Though if that compiles and runs, I'd check the results to make sure that's exactly what you want mathematically.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top