楼主: xingzhaoh
3271 4

[问答] R2WinBUGS包学习询问 [推广有奖]

副教授

21%

还不是VIP/贵宾

-

威望
0
论坛币
3407 个
通用积分
13.9254
学术水平
5 点
热心指数
6 点
信用等级
3 点
经验
601 点
帖子
427
精华
0
在线时间
703 小时
注册时间
2011-9-14
最后登录
2023-11-17

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
小弟初学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.

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


二维码

扫码加我 拉你入群

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

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

关键词:R2WinBUGS winbugs WINBUG BUGS bug 学习 function library schools

回帖推荐

epoh 发表于4楼  查看完整内容

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. ...

epoh 发表于2楼  查看完整内容

remember to go to "file>change dir...to enter the subdirectory where the file "nonlinearmodel.bug" is located.
沙发
epoh 发表于 2013-1-8 14:26:06 |只看作者 |坛友微信交流群
remember to go to "file>change dir...to enter
the subdirectory where the file "nonlinearmodel.bug" is located.

使用道具

藤椅
xingzhaoh 发表于 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"
这三个是什么意思?

希望得到你的指点

使用道具

板凳
epoh 发表于 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

# ------------------------------------------------
  1. model{
  2. for(i in 1:N){
  3. y[i] ~ dnorm(mu[i], tau)
  4. mu[i] <- alpha-beta*pow(gamma,x[i])
  5. }
  6. alpha ~ dnorm(0.0, 1.0E-6)
  7. beta ~ dnorm(0.0, 1.0E-6)
  8. gamma ~ dunif(0.0, 1.0)
  9. tau ~ dgamma(0.001, 0.001)
  10. }
复制代码


# ------------------------------------------------
###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).

已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
ltx5151 + 20 热心帮助其他会员
zhangtao + 5 + 5 + 5 精彩帖子

总评分: 论坛币 + 20  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

使用道具

报纸
xingzhaoh 发表于 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 ...
谢谢,灰常感谢

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-2 01:25