[R-sig-ME] examples of combining chains from MCMCglmm

Hans Ekbrand hans at sociologi.cjb.net
Wed Oct 10 12:03:53 CEST 2012


On Wed, Oct 03, 2012 at 08:09:27AM -0700, Joshua Wiley wrote:

> > Quoting Joshua Wiley <jwiley.psych at gmail.com> on Sun, 16 Sep 2012 13:01:09
> > -0700:
> >
> >> Hi All,
> >>
> >> Just wondering if anyone has examples lying around of combining chains
> >> from different runs of MCMCglmm on the same model?  If anyone does,
> >> I'd love to look at some.  Ideally they would be generalized (i.e.,
> >> able to combine an arbitrary number of chains).  If not, once I am
> >> done I will probably make a little example and post it somewhere.


> I did still wonder about combining the chains.  

Here is code that runs MCMCglmm on three hosts in a snow cluster
("hans-vita", "hans" and "ingers"), and combines the resulting chains.

library(MCMCglmm)
library(snow)
hosts <- c("hans-vita", "hans", "ingers")
cl <- makeCluster(hosts, type = "SOCK")
clusterEvalQ(cl, data(Traffic, package = 'MASS'))
clusterEvalQ(cl, Traffic$year <- as.factor(Traffic$year))
clusterEvalQ(cl, library(MCMCglmm))
prior <- list(R = list(V = 1, nu = 0.002), G = list(G1 = list(V = 1e+08, fix = 1)))
clusterExport(cl, "prior")
my.mcmc.lists <- parLapply(cl, rep(8000, length(hosts)), function(x) { MCMCglmm(y ~ limit + day, random = ~year, family = "poisson", data = Traffic, prior = prior, verbose = FALSE, pr = TRUE, nitt=x, thin=10, burnin=3000)$Sol })
stopCluster(cl)
library(coda)
summary(mcmc.list(my.mcmc.lists))$quantiles[2,]

-- 
Hans Ekbrand (http://sociologi.cjb.net) <hans at sociologi.cjb.net>



More information about the R-sig-mixed-models mailing list