JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for BUGS Archives


BUGS Archives

BUGS Archives


BUGS@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

BUGS Home

BUGS Home

BUGS  February 2012

BUGS February 2012

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: How to create a loop without command "for" in Bugs?

From:

Timothy Handley <[log in to unmask]>

Reply-To:

[log in to unmask]

Date:

Tue, 14 Feb 2012 09:24:27 -0800

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (110 lines)

)) 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[j-1]+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
805-658-5759 (CHIS)
805-370-2396 (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

Top of Message | Previous Page | Permalink

JISCMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


WWW.JISCMAIL.AC.UK

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager