全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3481 4
2013-01-06
小弟初学R2WinBUGS包,在依葫芦画瓢拷贝code时发现下面的错误:
1:
library("R2WinBUGS")
data(schools)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list("J","y","sigma.y")
inits <- function(){
list(theta=rnorm(J,0,100),mu.theta=rnorm(1,0,100),
sigma.theta=runif(1,0,100))
}
schools.sim = bugs(data,inits,
model.file="hierarchicalmodel.bug",
parameters=c("theta","mu.theta","sigma.theta"),
n.chains=3,n.iter=2000,n.burnin=1000,n.thin=1,
bugs.directory="c:/Program Files/WinBUGS14/",
codaPkg=FALSE)
错误于bugs(data, inits, model.file = "hierarchicalmodel.bug", parameters = c("theta",  :
  hierarchicalmodel.bug does not exist.


2
x = c(1.0,1.5,1.5,1.5,2.5,4.0,5.0,5.0,7.0,8.0,8.5,
9.0,9.5,9.5,10.0,12.0,12.0,13.0,13.0,14.5,
15.5,15.5,16.5,17.0,22.5,29.0,31.5)
y = c(1.80,1.85,1.87,1.77,2.02,2.27,2.15,2.26,2.47,
2.19,2.26,2.40,2.39,2.41,2.50,2.32,2.32,2.43,
2.47,2.56,2.65,2.47,2.64,2.56,2.70,2.72,2.57)
N <- length(x)
data <- list("x","y","N")
inits <- function(){
list(alpha=1,beta=1,tau=1,gamma=0.9)
}
nonlinear.sim = bugs(data,inits,
model.file="nonlinearmodel.bug",
parameters=c("alpha","beta","tau","gamma"),
n.chains=1,n.iter=10000,n.burnin=5000,n.thin=1,
bugs.directory="c:/Program Files/WinBUGS14/",
codaPkg=FALSE)

错误于bugs(data, inits, model.file = "nonlinearmodel.bug", parameters = c("alpha",  :
  nonlinearmodel.bug does not exist.

初次使用,摸不清头脑,请高手指点一下,万分感激


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-1-8 14:26:06
remember to go to "file>change dir...to enter
the subdirectory where the file "nonlinearmodel.bug" is located.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-1-8 15:05:42
epoh 发表于 2013-1-8 14:26
remember to go to "file>change dir...to enter
the subdirectory where the file "nonlinearmodel.bug"  ...
1 nonlinearmodel是下面形式:
model;
{
for( j in 1 : J ) {
theta[j] ~ dnorm(mu.theta,tau.theta)
}
for( j in 1 : J ) {
y[j] ~ dnorm(theta[j],tau.y[j])
}
mu.theta ~ dnorm( 0.0,1.0E-6)
tau.theta <- pow(sigma.theta, -2)
for( j in 1 : J ) {
tau.y[j] <- pow(sigma.y[j], -2)
}
sigma.theta ~ dunif(0,100)
}
怎么样才可以生成nonlinearmodel.bug

2"theta","mu.theta","sigma.theta"
这三个是什么意思?

希望得到你的指点
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-1-9 16:21:18
xingzhaoh 发表于 2013-1-8 15:05
1 nonlinearmodel是下面形式:
model;
{
SAVE THE FOLLOWING MODEL IN FILE "nonlinearmodel.bug" or "nonlinearmodel.txt"
and place in c:\xingzhaoh\nonlinearmodel.txt

# ------------------------------------------------
复制代码


# ------------------------------------------------
###in R Console
library(R2WinBUGS)
x = c( 1.0,  1.5,  1.5,  1.5, 2.5,   4.0,  5.0,  5.0,  7.0, 8.0,  8.5,  9.0,  9.5, 9.5,  
      10.0, 12.0, 12.0, 13.0, 13.0, 14.5, 15.5, 15.5, 16.5, 17.0, 22.5, 29.0, 31.5)

y = c(1.80, 1.85, 1.87, 1.77, 2.02, 2.27, 2.15, 2.26, 2.47, 2.19, 2.26, 2.40, 2.39, 2.41,
      2.50, 2.32, 2.32, 2.43, 2.47, 2.56, 2.65, 2.47, 2.64, 2.56, 2.70, 2.72, 2.57)

N       <- length(x)
data    <- list("x","y","N")
inits   <- function(){
  list(alpha = 1, beta = 1, tau = 1, gamma = 0.9)
}

nonlinear.sim = bugs(data,inits,model.file="nonlinearmodel.txt",
                     parameters=c("alpha","beta","tau","gamma"),n.chains=1,
                     n.iter=10000,n.burnin=5000,n.thin=1,working.directory = "c:/xingzhaoh/",
                     bugs.directory="c:/Program Files/WinBUGS14/",codaPkg=FALSE)
print(nonlinear.sim,digits=4)

Inference for Bugs model at "nonlinearmodel.txt", fit using WinBUGS,
1 chains, each with 10000 iterations (first 5000 discarded)
n.sims = 5000 iterations saved
             mean      sd     2.5%      25%      50%      75%    97.5%
alpha      2.6547  0.0708   2.5390   2.6060   2.6460   2.6940   2.8240
beta       0.9716  0.0759   0.8227   0.9222   0.9710   1.0192   1.1250
tau      109.8187 32.3728  56.2797  86.6275 107.0000 129.6000 181.4000
gamma      0.8641  0.0307   0.7938   0.8466   0.8663   0.8851   0.9174
deviance -49.1569  3.0536 -52.9900 -51.4300 -49.8700 -47.5100 -41.6598

DIC info (using the rule, pD = Dbar-Dhat)
pD = 3.8 and DIC = -45.3
DIC is an estimate of expected predictive error (lower deviance is better).

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-1-10 08:48:46
epoh 发表于 2013-1-9 16:21
SAVE THE FOLLOWING MODEL IN FILE "nonlinearmodel.bug" or "nonlinearmodel.txt"
and place in c:\x ...
谢谢,灰常感谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群