Print

Print


On 04/08/16 16:00, subrata sarker wrote:
[log in to unmask]" type="cite">
Hello,

I am trying to run a model in OpenBUGS. But I am getting an error "Variable TT is not defined". Here is my BUGS code:

That's a R issue: you haven't given any of the variables of sp.data a name:

> Data=structure(.Data=c(0.1, 0.2, 0.5, 0.2, 0.2, 0.8, 0.2, 0.4, 0.3, 0.2, 0.1, 0.6, 0.1, 0.5, 0.6), .Dim=c(5,3))
> TT=nrow(Data)
> N=ncol(Data)
> y=as.matrix(Data)
> sp.data = list(y, N, TT)
> str(sp.data)
List of 3
 $ : num [1:5, 1:3] 0.1 0.2 0.5 0.2 0.2 0.8 0.2 0.4 0.3 0.2 ...
 $ : int 3
 $ : int 5

Try
sp.data = list(y=y, N=N, TT=TT)
You might also want to debug this directly in BUGS: I don't think you mean dmnorm() for y (should be dnorm?), and you also don't define y[1,] (i.e. the initial year). If you do this, use the BRugs package to write the data (the order of indices are different, for historical reasons).

Bob

[log in to unmask]" type="cite">
model{
   for(t in 2:TT){
    for(i in 1:N){
y[t,i] ~ dmnorm(y1[t,i], tau[i])
     } 
y1[t,1] <- (p[1,1] * y[t-1,1]) + (p[1,2] *y[t-1,2]) + (p[1,3] *y[t-1,3])
y1[t,2] <- (p[2,1] * y[t-1,1]) + (p[2,2] *y[t-1,2]) + (p[2,3] *y[t-1,3])
y1[t,3] <- (p[3,1] * y[t-1,1]) + (p[3,2] *y[t-1,2]) + (p[3,3] *y[t-1,3])
  }
    for (s1 in 1:N) {
        for (s2 in 1:N) {
        p[s1, s2]~ dnorm(1, 1)
                         }
                      }
for(i in 1:N){
tau[i] ~ dgamma(0.001, 0.001)
             }    
}

Here is my data and R code to run the BUGS code:

Data=structure(.Data=c(0.1, 0.2, 0.5, 0.2, 0.2, 0.8, 0.2, 0.4, 0.3, 0.2, 0.1, 0.6, 0.1, 0.5, 0.6), .Dim=c(5,3))
TT=nrow(Data)
N=ncol(Data)
y=as.matrix(Data)
sp.data = list(y, N, TT)

Sp.sim0<- bugs (sp.data, inits=NULL, 
           parameters=c('p'),  model.file= "model2.txt",n.chains=2,  DIC=TRUE,n.iter=1000, codaPkg=FALSE,debug=TRUE)

Can any please help to t solve this problem? 


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


-- 

Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 7542 1863
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://blogs.nature.com/boboh
Journal of Negative Results - EEB: www.jnr-eeb.org 
------------------------------------------------------------------- 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