Marta
Marta

Reputation: 3843

WinBUGS: Multiple definitions of a node

I want to define the local level model in Winbugs. The model is syntactically correct. But when I run, I got this error: "multiple definitions of node y[1]"

    model {

        for (i in 1:T)
            {epsilon[i]~dnorm(0,h)
                u[i]~dnorm(0,eta_h)}    

        a[1]<-a1    
        for (j in 2:T)
            {a[j]<-a[j-1]+u[j]}

        for (k in 1:T)
            {y[k]<-a[k]+epsilon[k]}

    h~dgamma(0.0001,0.0001)
    eta~dgamma(0.0001,0.0005)
    eta_h<-eta*h

    }

    data list(T=10, a1=0.001)
    y[]
    -0.7224571
    -0.397027213
    3.1808741
    1.952424816
    4.921476096
    5.258244747
    4.383846014
    6.055572232
    5.474320734
    0.703784047
    END

Can you please tell me why and how to solve this? I've searched around on the error but each has their own specific case and there's not a generic solution or explanation as to why this arises.

Upvotes: 0

Views: 124

Answers (1)

jaradniemi
jaradniemi

Reputation: 618

There is a generic solution, namely "you've defined y[1] at least twice."

In this case, you have defined it once in your data and also in the line

y[k] <- ...

Upvotes: 1

Related Questions