Skip to content

Computing ergodic mean with CODA

3 messages · Raquel Guimarães, Ben Bolker, Giovanni Petris

#
Hi all,

I would like to compute ergodic mean using MCMC output from WinBUGS. I 
tried using CODA package, but it seems that it is not implemented yet.

Could anyone help me to compute this? Attached to this email are my 
output and index files.

Kind regards,

Raquel

--
Raquel Rangel de Meireles Guimar?es
Doutoranda em Demografia
raquel at cedeplar.ufmg.br
http://ufmg.academia.edu/RaquelGuimaraes
Cedeplar - Centro de Desenvolvimento e Planejamento Regional
Avenida Ant?nio Carlos, 6627, Sala 2090, Pampulha, BH-MG
Telefones: (31) 3409-7144 - (31) 9732-2132
Faculdade de Ci?ncias Econ?micas, UFMG (http://www.cedeplar.ufmg.br)

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: index-full.ind
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101107/999a51f6/attachment.pl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: out-full.out
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101107/999a51f6/attachment-0001.pl>
#
Raquel Rangel de Meireles Guimar?es <raquelrguimadem <at> gmail.com> writes:
[the data were not in the most convenient form; 
one of the preferences is for a *small* reproducible
example ...  I cut & pasted them into a file to
recreate the original mcmc object].

  Based on a quick look at [Ntzoufras, Ioannis. 2009. Bayesian modeling using
WinBUGS. John Wiley and Sons.], I think cumsum(x)/(1:length(x)) is the
ergodic mean (essentially a running cumulative mean).


x <- read.table("~/R/misc/ergod.dat")
library(coda)
v <- as.mcmc(matrix(x[,2],nrow=5000))
em <- sweep(apply(v,2,cumsum),1,(1:nrow(v)),"/")
library(reshape)
m <- melt(em)
xyplot(value~X1|X2,type="l",data=m,
       scales=list(y=list(relation="free")))
#
Hola Raquel,

As Ben already told you, ergodic means are pretty easy to compute from
scratch. If you are lazy, or you want something more, like estimated
standard errors, you can check out the functions ergMean and mcmcMean in
package dlm.

Best,
Giovanni Petris

On Sun, 2010-11-07 at 14:34 -0200, Raquel Rangel de Meireles Guimar?es
wrote: