在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
用这个包调用BUGS model,分别用表格和图形概述inference和convergence,保存估计的结果 as.bugs.array 转换成bugs object函数把马尔科夫链估计结果(不是来自于BUGS),转成BUGS object,主要用来plot.bugs 展示结果。 as.bugs.array(sims.array, model.file=NULL, program=NULL, DIC=FALSE, DICOutput=NULL, n.iter=NULL, n.burnin=0, n.thin=1) sims.array :3维数组 n.keep, n.chains和combined parameter vector的长度 model.file : OpenBUGS编写的.odc 模型文件 DIC : 是否计算DIC曲线 DICOutput : DIC值 n.iter :生成sims.array 每条chain 迭代数 n.burnin :丢弃的迭代次数 n.thin :thinning rate attach.all 添加数据到搜索路径The database is attached/detached to the search path,While attach.all attaches all elements of an object x to a database called name, attach.bugs attaches all elements of x$sims.list to the database bugs.sims itself making use of attach.all. attach.all(x, overwrite = NA, name = “attach.all”) attach.bugs(x, overwrite = NA) detach.all(name = “attach.all”) detach.bugs() x : bugs 对象 overwrite :TRUE 删除全局环境中被掩盖的数据, NA 询问,FALSE name : 环境name bugs 最重要,用R运行bugs自动输入值,启动bugs,保存结果 bugs(data, inits, parameters.to.save, n.iter, model.file=“model.txt”, n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, OpenBUGS.pgm=NULL, working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, save.history=(.Platform$OS.type == “windows” | useWINE==TRUE), over.relax = FALSE) data :模型中使用的数据 inits :n chain 的元素列表,每一个要素是一个模型初始值列表,或者一个生成初始值得function parameters.to.save : 需要被记录的参数名向量 model.file : model 文件.txt n.chains : 默认3条 n.iter :每条链的迭代次数,默认2000 n.thin : Thinning rate. 正整数,默认是1, saveExec :使用basename(模型.file)保存OpenBUGS执行的重新启动映像。 restart :执行从上次执行的最后状态恢复,存储在工作目录中的.bug文件中。 debug : 默认FALSE,正在运行行时Openbugs 页面关闭 DIC :计算deviance,,pD,和DIC。 digits :有效小数位数 codaPkg :FALSE 返回 bugs对象,否则输出,用coda 包 read.bugs 读取, OpenBUGS.pgm :通向OpenBUGS可执行程序的完整路径。 working.directory:OpenBUGS的输入和输出将存储在此目录中; clearWD :是否这些文件的“data.txt”、“init(1:n.chains). txt”,“log.odc”、“codaIndex.txt”和“coda[1:nchain].txt”结束时删除。 bugs.seed :OpenBUGS随机种子,1-14整数 summary.only : TURE ,仅对非常快速的分析给出了一个参数概要 save.history : TURE,最后画出trace
model { for (j in 1:J){ y[j] ~ dnorm (theta[j], tau.y[j]) theta[j] ~ dnorm (mu.theta, tau.theta) tau.y[j] <- pow(sigma.y[j], -2) } mu.theta ~ dnorm (0.0, 1.0E-6) tau.theta <- pow(sigma.theta, -2) sigma.theta ~ dunif (0, 1000) }
bugs.data 生成输入文件bugs.data(data, dir = getwd(), digits = 5, data.file = “data.txt”) bugs.inits 生成初始值文件bugs.inits(inits, n.chains, digits, inits.files = paste(“inits”, 1:n.chains, “.txt”, sep = “”)) bugs.log 读取log文件(summary statistics and DIC information)bugs.log(file) plot.bugs 画bugs对象plot(x, display.parallel = FALSE, …) display.parallel :在摘要图的两部分中显示平行的间隔 print.bugs 输出bugs对象print(x, digits.summary = 1, …) digits.summary:四舍五入的位数 read.bugs读Markov链蒙特卡罗输出的CODA格式。并返回一个类mcmc.list对象。使用coda包进行进一步的输出分析列表。 read.bugs(codafiles, …) validateInstallOpenBUGS 比较R和openbugs软件运行结果write.model 转化R function创建模型文件
LS0tDQp0aXRsZTogIlLor63oqIDvvJpSMk9wZW5CVUdTIg0Kb3V0cHV0OiBodG1sX25vdGVib29rDQotLS0NCiMgUuivreiogO+8mlIyT3BlbkJVR1MNCg0K55So6L+Z5Liq5YyF6LCD55SoQlVHUyBtb2RlbCzliIbliKvnlKjooajmoLzlkozlm77lvaLmpoLov7BpbmZlcmVuY2Xlk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