In R, c(3,1,0) * c(2,0,1) == c(6,0,0). This is not dot product and it's not cross product. First, what is the name for this product, and second, does it work in WinBUGS, OpenBUGS and/or JAGS?
4 Answers
Unlike JAGS, WinBUGS and OpenBUGS does not do this form of vectorization; you have to write a loop, and compute each element 'by hand', as described above.
Martyn Plummer points out that this is implemented in JAGS, which I missed when reading the manual. From Ch 5:
Scalar functions taking scalar arguments are automatically vectorized. They can also be called when the arguments are arrays with conforming dimensions, or scalars. So, for example, the scalar $c$ can be added to the matrix $A$ using
B <- A + c
instead of the more verbose form
D <- dim(A) for (i in 1:D[1]) for (j in 1:D[2]) { B[i,j] <- A[i,j] + c } }
To do element-wise multiplication you can just make a for loop in those languages and that's it! I've used for loops in WinBUGS with no problems.
-
$\begingroup$ What question does this reply address? It does not seem to be relevant here. $\endgroup$– whuber ♦Commented Jan 6, 2012 at 23:46
-
$\begingroup$ @whubber, why? It is perfectly relevant. Ok, I changed the post a little to be more clear. $\endgroup$– TomasCommented Jan 6, 2012 at 23:49
-
$\begingroup$ Yup, a for loop is what I've been doing so far; I'd just wondered if a vectorized version was possible. $\endgroup$ Commented Jan 6, 2012 at 23:59
-
$\begingroup$ I've submitted a feature request to JAGS: sourceforge.net/tracker/… $\endgroup$ Commented Jan 7, 2012 at 0:04
-
$\begingroup$ Thanks, Tomas. Now I see the connection: you're not answering the question as stated, but you are offering a workaround. $\endgroup$– whuber ♦Commented Jan 7, 2012 at 0:08
Incidentally, element-wise multiplication of two equal length vectors is called the Hadamard product (aka the Schur product).