“节点a的多个定义"指的是节点a的多个定义. Winbugs中的错误 [英] "Multiple definition of node a" error in Winbugs

查看:226
本文介绍了“节点a的多个定义"指的是节点a的多个定义. Winbugs中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我只是重写了我的代码.现在的问题是,当我编译它时,出现节点a的多个定义" 的错误.有人知道我的代码有什么问题吗?我为模型创建了变量a,b和c,使其没有太多常量.

okay i just rewrite my code. Now the problem is when i compile it, I get an error of "multiple definition of node a". Do anyone know what wrong in my code. I create the variable a,b and c for the model not to have many constants.

  model{



  for(i in 1:n){


            a <- (k[1] + step(s1[i]-.9)*k[2] + step(s1[i]*.5-.9)*k[3]) 
            b <- (r[1] + step(s2[i]-.9)*r[2] + step(s2[i]*.5-.9)*r[3])
            c <- (s[1] + step(s3[i]-.9)*s[2] + step(s3[i]*.5-.9)*s[3])


    dummy[i] <- 0

      dummy[i] ~ dloglik(logLike[i])

      # This is the log transformation of the 3-variate poisson 

      logLike[i] <- -theta12[i] + a*log(theta12[i]) - logfact(a) -theta13[i] - b*log(theta13[i]) - logfact(b)-theta23[i] - c*log(theta23[i]) - logfact(c)-theta1[i] + (y1[i]-a-b)*log(theta1[i]) + logfact(y1[i]-a-b)-theta2[i] + (y2[i]-a-c)*log(theta2[i]) + logfact(y2[i]-a-c)-theta3[i] + (y3[i]-b-c)*log(theta3[i]) + logfact(y3[i]-b-c)





            log(theta1[i]) <- alpha1 + beta1*log(L[i])
            log(theta2[i]) <- alpha2 + beta2*log(L[i])
            log(theta3[i]) <- alpha3 + beta3*log(L[i])
            log(theta12[i]) <- alpha4 + beta4*log(L[i])
            log(theta23[i]) <- alpha5 + beta5*log(L[i])
            log(theta13[i]) <- alpha6 + beta6*log(L[i])
    }

            alpha1 ~ dgamma(.001, .001)
            alpha2 ~ dgamma(.001, .001)
            alpha3 ~ dgamma(.001, .001)
            alpha4 ~ dgamma(.001, .001)
            alpha5 ~ dgamma(.001, .001)
            alpha6 ~ dgamma(.001, .001)
            beta1 ~ dgamma(.001, .001)
            beta2 ~ dgamma(.001, .001)
            beta3 ~ dgamma(.001, .001)
            beta4 ~ dgamma(.001, .001)
            beta5 ~ dgamma(.001, .001)
            beta6 ~ dgamma(.001, .001)




    }


    data
    list(y1 =c(0,1,2,3,2),
    y2 = c(1,2,3,0,2),
    y3 = c(1,3,2,3,2),
    k =   c(0,1,2,3,4),
    s =   c(0,1,2,3,4), 
    r =    c(0,1,2,3,4), 
    L =   c(1,2,3,4,5), 
    s1= c(0,1,2,0,2), 
    s2= c(0,0,0,0,0),
    s3=  c(1,1,0,0,0),n=5)


    inits
    list(beta1=0,beta2=0,beta3=0,beta4=0,beta5=0,beta6=0,alpha1=0,alpha2=0,alpha3=0,
    alpha4=0,alpha5=0,alpha6=0)

推荐答案

由于在for()循环中定义了a,b,c,您会收到此错误.换句话说,您已经定义了一个常数节点多次(n次).您应将a,b,c替换为a [i],b [i],c [i].将BUGS视为模型描述语言,而不是编程语言.模型中的每个数量都必须具有一个单一的定义,作为其他数量的固定或随机函数.

You get this error because you've defined a, b, c within a for() loop. In other words you've defined a constant node multiple times (n times). You should replace a, b, c with a[i], b[i], c[i]. Think of BUGS as a model description language, not a programming language. Every quantity in your model has to have one single definition as a fixed or random function of other quantities.

这篇关于“节点a的多个定义"指的是节点a的多个定义. Winbugs中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆