Skip to content
Prev 81603 / 398503 Next

Double FOR

One way would be explicitly create your data first:
df <- expand.grid(a = 1:5, b= 1:5, c=1:5)

And then take advantage of vectorisation to compute DIC.hat:
with(df, sum(-2*((log(1/sqrt(2*pi*a^2))*exp((((b-c)/a)^2)/-2))))

which looks awfully like differences of two normal densities, so you
might be able to use dnorm (which might be faster as it is written
purely in C (but not noticeably so unless you have a lot of data), but
will make your algorithm more clear).

By breaking it down into multiple steps, hopefully you can get a
better idea of what's going on.  Putting browser() in the middle of
your loop would be another way for you to check out what is really
happening.

Hadley
On 11/26/05, Ginestet, Cedric <c.ginestet at imperial.ac.uk> wrote: