)) I've been successful using the sum function in BUGS. For example
##Define the things you want to sum
for(j in 1:k)
{ a[j] < (whatever) }
##Calculate the sum
sum.of.a < sum(a[1:k])
##Note that, unlike S+ or R, sum(a) doesn't work. You must give the indices
of a that you wish to sum over.
)) You can also calculate a sum using a loop, it's just awkward. For
example:
##Define the things you want to sum
for(j in 1:k)
{a[j] < (whatever) }
##Calculate the sum
l[1] < a[1]
for(i in 2:k)
{ l[j] < l[j1]+a[j] }
##The node l[k] is now the sum of all the a[j]
)) I don't understand the log problem. Could you repost with more
information?
)) Remember that this is a descriptive language not an imperative language.
It may look like C or Java, but it's not. As you noticed, you cannot
redefine a node as x=x+y. But you can define as many new nodes as you like,
as z=x+y. So you can do most of the same calculations as in an imperative
language, you just need to write slightly different code, in which you make
a new node for every new value.
Tim Handley
Research Assistant
Mediterranean Network, NPS
8056585759 (CHIS)
8053702396 (SAMO)

Date: Mon, 13 Feb 2012 12:55:46 +0000
From: Felipe bhering <[log in to unmask]>
Subject: How to create a loop without command "for" in Bugs?
I'll try to make an example to make it easier to understand the question.
model{
constant1=(number)
constan2=(number)
for(j in 1:k){ #k defined in data
a[j] ~ dgamma(c[j],d[j])
b[j]~ dgamma(e[j], f[j])
c[j] ~ dgamma(constan1,constant2)
d[j] ~ dgamma(constan1,constant2)
e[j] ~ dgamma(constan1,constant2)
f[j] ~ dgamma(constan1,constant2) }
l[i]<
}
I want to make a likelihood ( l ) that is a sum of elements in 1:k (for
each i => a simple loop would solve it..), but unlike R, in bugs I cannot
make a for() function or a sum function to make l[i] (multiple
definitions..).
It's impossible to do something like this in bugs (it accepts only one
specification).
for(i in N){ #N is a number defined on data, k also
l[i]<0
for(j in 1:k){
l[i]<l[i]+
d[j]*log(c[j])log(d[j])+loggam(c[i])+pow(a[j],b[j])+a[j]*t[i] +
delta[i]*a[j]
#it's just an example.. t and delta is in data
}
}
I tried to make this l[i] using functions sum and inprod, bugs doesn't
allow to make log() of a function.
Also, i keep getting errors when i use inprod with 2 "distributions", like
c and d (inprod(d,c)).
And, if I make a l[i] specification directly with a sum all 1:k it gets a
error of complex/too many constants.
Any idea how to write it in a simple way and make a sum all at once of all
1:k?
I am stucked, would be very usefull any comment.
Thanks in advance.

This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
