【问题标题】:Passing variable to WinBugs model in R将变量传递给R中的WinBugs模型
【发布时间】:2015-03-11 16:51:50
【问题描述】:

我正在使用 R2WinBugs 包。我想将之前在 R 脚本中计算的两个参数传递给模型函数

c0yy <- 0.1
syy <- 0.0001
#Model
model <- function(c0yy,syy){

  #Likelihood
  for(i in 1:n){
    y[i] ~ dnorm(mu[i],cyy)
  }

  #Regression formula
  for(i in 1:n){
    mu[i] <- alpha + gamma * x[i]
  }

  #Priors for the regression parameters
  alpha ~ dnorm(0,0.000001)
  gamma ~ dnorm(0,0.000001)

  #Priors for the precision parameter
  cyy ~ dnorm(c0yy,syy)

  #Monitored variables
  beta <- gamma/(alpha-1)  
}
filename <- file.path(tempdir(), "Olm.txt")
write.model(model, filename)

但我收到此错误

made use of undefined node c0yy

如果我在模型函数中替换 c0yysyy 的值,它可以工作。有帮助吗?

谢谢

【问题讨论】:

    标签: r winbugs r2winbugs


    【解决方案1】:

    您要传递给模型的值是数据。在 BUGS(和 R2WinBUGS)中,数据作为与您定义的模型不同的实体传递给程序。为了包含数据,您可以将它们放入列表中,例如;

    my.mcmc <- bugs(data = list(c0yy = 0.1, syy= 0.0001), params = "beta', model.file = "Olm.txt", n.iter=10000) 
    

    您还需要从模型脚本中删除 &lt;- function(c0yy,syy)

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2017-11-10
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多