如何在R中调用winbugs

Python021

如何在R中调用winbugs,第1张

以下例子有如何用R调用winbugs,如果是openbugs需要加载另外一个

># 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'类型实现默认的方法

语法及Prior distributions有错的地方, 都已帮你更正. A2=0,表示有误,请自行更改. 运行结果如下: Inference for Bugs model at "rabbit.bug", fit using WinBUGS, 1 chains, each with 13000 iterations (first 3000 discarded) n.sims = 10000 iterations saved meansd 2.5% 25% 50% 75% 97.5% a1.001 0.001 1.000 1.000 1.000 1.001 1.002 b4.979 0.021 4.924 4.971 4.985 4.994 5.000 p4.976 0.025 4.911 4.966 4.983 4.993 4.999 q3.002 0.002 3.000 3.001 3.002 3.003 3.008 k1.002 0.002 1.000 1.001 1.001 1.003 1.007 logl -1876.811 2.236 -1882.000 -1878.000 -1876.000 -1875.000 -1873.000 A2 0.000 0.000 0.000 0.000 0.000 0.000 0.000 deviance 5227.280 4.458 5221.000 5224.000 5227.000 5230.000 5238.000 DIC info (using the rule, pD = Dbar-Dhat) pD = 0.0 and DIC = 5227.3 DIC is an estimate of expected predictive error (lower deviance is better). Ps: Prior distributions dunif() 的范围请自行更改决定 以上仅供参考 rabbit.bug