首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在BRugs中找到后验模式

问如何在BRugs中找到后验模式
EN

Stack Overflow用户
提问于 2014-02-19 08:02:08
回答 1查看 858关注 0票数 3

我正在尝试使用R包"BRugs“来实现Gibbs采样器,但是生成汇总后验统计信息的函数,如samplesStats(),只返回平均值和中位数。是否有可能提取后验模式?

EN

回答 1

Stack Overflow用户

发布于 2014-02-19 18:01:29

通过使用BRugs帮助文件中的示例,samplesSample函数将为您提供完整的MCMC。

代码语言:javascript
复制
###    Step by step example:    ###
library("BRugs") # loading BRugs

## Prepare the example files in a temporary directory
exfiles <- dir(options()$OpenBUGSExamples, pattern="^Rats.*txt$", full.names=TRUE)
ok <- file.copy(exfiles, tempdir())

## Now setting the working directory to the temporary one:
oldwd <- setwd(tempdir())

## some usual steps (like clicking in WinBUGS):
modelCheck("Ratsmodel.txt")          # check model file
modelData("Ratsdata.txt")            # read data file
modelCompile(numChains=2)            # compile model with 2 chains
modelInits(rep("Ratsinits.txt", 2))  # read init data file
modelUpdate(1000)                    # burn in
samplesSet(c("alpha0", "alpha"))     # alpha0 and alpha should be monitored
modelUpdate(1000)                    # 1000 more iterations ....

我们可以提取MCMC样本,比如alpha节点,然后通过

代码语言:javascript
复制
alpha0<-samplesSample("alpha0")
hist(alpha0)

​

​

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21868230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档