How to find rear mode in BRugs

I am trying to use the "BRugs" R-packages to implement the Gibbs sampler, however functions that produce summary statistics of the rear frequencies, for example samplesStats (), return only the middle and middle. Can I remove the rear mode?

+3
source share
1 answer

The function samplesSamplewill provide you with a complete MCMC to illustrate using the example in the help file BRugs...

###    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 ....

You can extract an MCMC sample, such as alphanode, and do whatever you like with it,

alpha0<-samplesSample("alpha0")
hist(alpha0)

enter image description here

+2
source

All Articles