我正在尝试使用R包"BRugs“来实现Gibbs采样器,但是生成汇总后验统计信息的函数,如samplesStats(),只返回平均值和中位数。是否有可能提取后验模式?
发布于 2014-02-19 18:01:29
通过使用BRugs帮助文件中的示例,samplesSample函数将为您提供完整的MCMC。
### 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节点,然后通过
alpha0<-samplesSample("alpha0")
hist(alpha0)

https://stackoverflow.com/questions/21868230
复制相似问题