楼主: 铤而走险
13984 21

[问答] 请教R中运行WINbugs问题 [推广有奖]

  • 0关注
  • 2粉丝

硕士生

36%

还不是VIP/贵宾

-

威望
0
论坛币
103 个
通用积分
2.8000
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1048 点
帖子
117
精华
0
在线时间
108 小时
注册时间
2009-10-3
最后登录
2025-8-18

楼主
铤而走险 发表于 2012-4-27 12:38:57 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我的程序运行后有这样的错误提示:
错误于is.finite(x) : 没有为'list'类型实现默认的方法,这是什么意思?
> # R code with interface to Winbugs
>
> library(R2WinBUGS)   
> y<-read.table("D:/Bugs/jump.dat",header=TRUE)    #import data#
> N<-length(y)
> Xi0<-rep(0,N)   # Give initial values to state variables#
> J0<-rep(0,N)
> data<-list("N","y")  
> # Give initial values to the parameters for winbugs #
> inits <-function() {list ( tau=2,
+                    Jtau=2,
+                    mu=0,
+                    Jmu=0,
+                    lamda = 0.05, Xi=Xi0,J=J0)}
> parameters<- c("Sigma","JSigma","mu","Jmu","lamda","Xi","J")
> # quote the winbugs#
> jump.sim<-bugs (data, inits=inits, parameters, "model.bug", n.chains=3, n.iter=1000,debug=TRUE,
+                      DIC=TRUE,bugs.directory = "D:/Program Files/WinBUGS14/",working.directory = "D:/Bugs")
错误于is.finite(x) : 没有为'list'类型实现默认的方法
>


二维码

扫码加我 拉你入群

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

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

关键词:winbugs WINBUG BUGS bug Win interface library initial values 程序

本帖被以下文库推荐

沙发
epoh 发表于 2012-4-28 16:19:13
y<-read.table("D:/Bugs/jump.dat",header=TRUE)    #import data#
y=y[,1]

藤椅
铤而走险 发表于 2012-4-28 21:32:59
epoh 发表于 2012-4-28 16:19
y
按照您的建议修改后又提示:
错误于FUN(X[[2L]], ...) : 不能改变因子的存储方式,这又是什么原因呢?

板凳
epoh 发表于 2012-4-28 22:09:20
铤而走险 发表于 2012-4-28 21:32
按照您的建议修改后又提示:
错误于FUN(X[[2L]], ...) : 不能改变因子的存储方式,这又是什么原因呢?
Error in FUN(X[[2L]], ...) :
  invalid to change the storage mode of a factor

这是数据格式问题
你数据传上来看看

报纸
铤而走险 发表于 2012-4-29 09:06:25
epoh 发表于 2012-4-28 22:09
Error in FUN(X[[2L]], ...) :
  invalid to change the storage mode of a factor
该程序是论坛上别人分享的,模型部分如下所示,数据在附件里,这是txt 格式的。请您帮忙看看到底问题在哪里!
modle {
     for (i in 1:N) {
              y ~dnorm(r,tau)    # tau corresponding to  
       r<-mu+Xi*J            # Xi corresponding to  #
       Xi[t]~dnorm(Jmu,Jtau)
        J[t]~dbern(lamda)
}
         Sigma<-1/sqrt(tau)
         JSigma<-1/sqrt(Jtau)
           mu~dnorm(0,1)       # prior distributions for parameters
           tau~dgamma(2, 2)
           Jmu~dnorm(0,1)
           Jtau~dgamma(2,2)
          lamda~dbeta(2,2)

} jump.txt (5.52 KB)

地板
铤而走险 发表于 2012-4-29 09:20:11
铤而走险 发表于 2012-4-29 09:06
该程序是论坛上别人分享的,模型部分如下所示,数据在附件里,这是txt 格式的。请您帮忙看看到底问题在哪 ...
我把y<-read.table("d:/Bugs/jump.dat")改为:y<-read.table("d:/Bugs/jump.txt")后可以运行了,但是Winbugs中什么结果也没有,运行的log 中视如下记录的,说各个参数都是update cannot be excuted,想请教是否程序本身有问题:
expected left pointing arrow <- or twiddles ~
data(D:/Bugs/data.txt)
command #Bugs:data cannot be executed (is greyed out)
compile(1)
inits(1,D:/Bugs/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(5)
update(1000)
command #Bugs:update cannot be executed (is greyed out)
set(Sigma)
command #Bugs:set cannot be executed (is greyed out)
set(JSigma)
command #Bugs:set cannot be executed (is greyed out)
set(mu)
command #Bugs:set cannot be executed (is greyed out)
set(Jmu)
command #Bugs:set cannot be executed (is greyed out)
set(lamda)
command #Bugs:set cannot be executed (is greyed out)
set(Xi)
command #Bugs:set cannot be executed (is greyed out)
set(J)
command #Bugs:set cannot be executed (is greyed out)
set(deviance)
command #Bugs:set cannot be executed (is greyed out)
dic.set()
command #Bugs:dic.set cannot be executed (is greyed out)
update(1000)
command #Bugs:update cannot be executed (is greyed out)
coda(*,D:/Bugs/coda)
command #Bugs:coda cannot be executed (is greyed out)
stats(*)
command #Bugs:stats cannot be executed (is greyed out)
dic.stats()

DIC
history(*,D:/Bugs/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(D:/Bugs/log.odc)
save(D:/Bugs/log.txt)

7
epoh 发表于 2012-4-29 10:06:20
铤而走险 发表于 2012-4-29 09:06
该程序是论坛上别人分享的,模型部分如下所示,数据在附件里,这是txt 格式的。请您帮忙看看到底问题在哪 ...
  1. modle {
  2.      for (i in 1:N) {
  3.      y[i] ~dnorm(r[i],tau)   
  4.      r[i]<-mu+Xi[i]*J[i]      
  5.      Xi[i]~dnorm(Jmu,Jtau) # normally distributed jump-sizes
  6.      J[i]~dbern(lamda)     # jumps-times Bernoulli distributed
  7. }
  8.      Sigma<-1/sqrt(tau)
  9.      JSigma<-1/sqrt(Jtau)
  10.      # prior distributions for parameters
  11.      mu~dnorm(0,1)      
  12.      tau~dgamma(2, 2)
  13.      Jmu~dnorm(0,1)
  14.      Jtau~dgamma(2,2)
  15.      lamda~dbeta(2,2)
  16. }
复制代码

8
铤而走险 发表于 2012-4-29 10:23:22
epoh 发表于 2012-4-29 10:06
您好!很抱歉又要打扰您!
按照您的模型运行后,调出Winbugs运行时还是没有参数估计出来,问题还是那样!
R中的错误提示是:
Error in file(con, "wb") : 无法打开链结
此外: 警告信息:
1: In file.create(to[okay]) :
  鐢变簬'Permission denied'鐨勫師鍥狅紝鏃犳硶寤虹珛'D:/Program Files/WinBUGS14//System/Rsrc/Registry_Rsave.odc'鏂囦欢
2: In file(con, "wb") :
  无法打开文件'D:/Program Files/WinBUGS14//System/Rsrc/Registry.odc': Permission denied
错误于bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE,  :
  Look at the log file and
try again with 'debug=TRUE' to figure out what went wrong within Bugs.
此外: 警告信息:
运行命令'"D:/Program Files/WinBUGS14//WinBUGS14.exe" /par "D:/Bugs/script.txt"'的状态是1

9
epoh 发表于 2012-4-29 11:03:34
铤而走险 发表于 2012-4-29 10:23
您好!很抱歉又要打扰您!
按照您的模型运行后,调出Winbugs运行时还是没有参数估计出来,问题还是那样! ...
library(R2WinBUGS)   
y<-read.table("D:/Bugs/jump.txt")    #import data#
y=y[,1]
t=length(y)
y=100*(log(y[2:t])-log(y[1:(t-1)]))
N<-length(y)
Xi0<-rep(0,N)   # Give initial values to state variables#
J0<-rep(0,N)
data<-list("N","y")  
# Give initial values to the parameters for winbugs #
inits <-function() {list ( tau=2,
                          Jtau=2,
                          mu=0,
                          Jmu=0,
                          lamda = 0.05, Xi=Xi0,J=J0)}
parameters<- c("Sigma","JSigma","mu","Jmu","lamda","Xi","J")

jump.sim<-bugs (data, inits=inits, parameters, "model.bug", n.chains=1, n.thin=1,
                n.iter=10000,n.burnin=5000,debug=TRUE,DIC=TRUE,
                bugs.directory = "D:/WinBUGS14/",working.directory = "D:/Bugs")

attach.bugs(jump.sim)
print(jump.sim,digits=4)

#################
Inference for Bugs model at "model.bug", 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%
Sigma       0.1627  0.0067    0.1500    0.1581    0.1626    0.1671    0.1762
JSigma      1.1700  0.0785    1.0350    1.1140    1.1650    1.2190    1.3440
mu          0.0499  0.0073    0.0354    0.0449    0.0498    0.0549    0.0640
Jmu         0.1773  0.0958   -0.0080    0.1123    0.1738    0.2392    0.3794
lamda       0.1990  0.0191    0.1630    0.1855    0.1989    0.2119    0.2375
Xi[1]       0.1654  1.1781   -2.1130   -0.6071    0.1267    0.9430    2.5780
Xi[2]       0.1736  1.1661   -2.1350   -0.5642    0.1355    0.9508    2.4491
Xi[3]       0.1747  1.1714   -2.1201   -0.6144    0.1444    0.9444    2.5400
.....
.....
J[804]      1.0000  0.0000    1.0000    1.0000    1.0000    1.0000    1.0000
J[805]      1.0000  0.0000    1.0000    1.0000    1.0000    1.0000    1.0000
J[806]      1.0000  0.0000    1.0000    1.0000    1.0000    1.0000    1.0000
deviance -788.9082 63.0674 -912.0050 -831.9250 -790.0000 -746.4000 -664.6875

DIC info (using the rule, pD = var(deviance)/2)
pD = 1988.7 and DIC = 1199.8
DIC is an estimate of expected predictive error (lower deviance is better).

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ryusukekenji + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

10
铤而走险 发表于 2012-4-29 11:37:45
epoh 发表于 2012-4-29 11:03
library(R2WinBUGS)   
y
非常感谢您,费心了,,还求出了收益率
但是很奇怪,为什么您能运行出来,我这就不行了。
我的Winbugs在D盘Program里,所以我把路径改为bugs.directory = "D:/Program Files/WinBUGS14/"
运行,怎么还是原来的提示,是不是我的Winbugs软件的问题,晕了!我再重装软件试试

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 09:45