Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R JAGS/bug中的pow()运算符_R_Jags_Winbugs - Fatal编程技术网

R JAGS/bug中的pow()运算符

R JAGS/bug中的pow()运算符,r,jags,winbugs,R,Jags,Winbugs,这可能不重要,但我好奇了一段时间 当在JAGS/BUG中构建模型时,我最初被教导使用pow()函数处理功率转换(例如tau它们在这一点上是相同的,因为至少JAGS版本4.0.0) 在jags论坛的特定帖子中,重要的内容是: Pow函数有别名“Pow”,因此可以作为“a^b”调用 或称为“战俘(a,b)” 继续使用你觉得更合适的一个。我相信原始pow函数的使用来自winbugs # first some fake data N <- 1000 x <- 1:N y <- x +

这可能不重要,但我好奇了一段时间


当在JAGS/BUG中构建模型时,我最初被教导使用
pow()
函数处理功率转换(例如
tau它们在这一点上是相同的,因为至少JAGS版本4.0.0)

在jags论坛的特定帖子中,重要的内容是:

Pow函数有别名“Pow”,因此可以作为“a^b”调用 或称为“战俘(a,b)”

继续使用你觉得更合适的一个。我相信原始
pow
函数的使用来自winbugs

# first some fake data
N <- 1000
x <- 1:N
y <- x + rnorm(N)

# model 1
cat('model {
  for (i in 1:N) {
    y[i] ~ dnorm(y.hat[i], tau)
    y.hat[i] <- a + b * x[i]
  }
  a ~ dnorm(0, .0001)
  b ~ dnorm(0, .0001)
  tau <- pow(sigma, -2)   ### this is the only difference
  sigma ~ dunif(0, 100)
}', file="test1.jags")

# model 2
cat('model {
  for (i in 1:N) {
    y[i] ~ dnorm(y.hat[i], tau)
    y.hat[i] <- a + b * x[i]
  }
  a ~ dnorm(0, .0001)
  b ~ dnorm(0, .0001)
  tau <- 1/(sigma*sigma)   ### this is the only difference
  sigma ~ dunif(0, 100)
}', file="test2.jags")
test.data <- list(x=x,y=y,N=N)

# give both a nice long run

system.time(test1.jags.out <- jags(model.file="test1.jags", data=test.data, 
                  parameters.to.save=c("a","b","tau","sigma"), n.chains=3, n.iter=100000))
   user  system elapsed 
 166.85    0.03  166.97 

system.time(test2.jags.out <- jags(model.file="test2.jags", data=test.data, 
                  parameters.to.save=c("a","b","tau","sigma"), n.chains=3, n.iter=100000))
   user  system elapsed 
 162.42    0.00  162.75