title: how to subtract two vectors in OpenBUGS
body: <p>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":</p>
  
  <pre><code>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] &lt;- inprod(K[i,] , vbeta[j,])
      }
      K[i,1] &lt;- 1.0
      for(j in 1:N) {
        K[i,j+1] &lt;- sum(ve[,i] - ve[,j])
      }
    }
  </code></pre>
  
  <p>If I change that line to <code>K[i,j+1] &lt;- sum(ve[,i]) - sum(ve[,j])</code>, then the model works fine, but that is not what I want to do. I would like to subtract element-wise.</p>
  
  <p>I searched SO for OpenBUGS, but there are only a few unrelated topics:</p>
  
  <p><a href="https://stackoverflow.com/questions/16094450/openbugs-problem">OpenBUGS - Variable is not defined</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9465825/openbugs-missing-value-in-bernoulli-distribution">OpenBUGS: missing value in Bernoulli distribution</a></p>
  
  <p>In Stats Stack Exchange there is this post which is close, but I still could not make how to implement this in my model:</p>
  
  <p><a href="https://stats.stackexchange.com/questions/20653/vector-multiplication-in-bugs-and-jags/20739#20739">https://stats.stackexchange.com/questions/20653/vector-multiplication-in-bugs-and-jags/20739#20739</a></p>
  
  <p>I understand I have to write a for loop, but this thing is sure giving me a big headache. :)</p>
  
  <p>I tried changing that line to:</p>
  
  <pre><code>for(k in 1:p) { temp [k] &lt;- ve[k,i] - ve[k,j] }
  K[i,j+1] &lt;- sum(temp[])
  </code></pre>
  
  <p>where 'p' is the number of rows in each 've'. Now I keep getting the error "multiple definitions of node temp[1]".</p>
  
  <p>I could definitely use some help. It will be much appreciated.</p>
  
  <p>Best regards to all and thanks in advance!</p>
  
  <p>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.</p>