datacloning / dclone

Data Cloning and MCMC Tools for Maximum Likelihood Methods
https://github.com/datacloning/dclone
7 stars 2 forks source link

bugs.parfit with OpenBUGS gives identical output #7

Closed psolymos closed 7 years ago

psolymos commented 7 years ago

The issue is described here. Summary: working.directory = getwd() in bugs.parfit leads to identical MCMC output.

psolymos commented 7 years ago

Reproduce the error:

library(dclone)
library(R2WinBUGS)
library(R2OpenBUGS)
data(schools)
#dput(schools)
schools <- structure(list(school = structure(1:8, .Label = c("A", "B", "C",
    "D", "E", "F", "G", "H"), class = "factor"), estimate = c(28.39,
    7.94, -2.75, 6.82, -0.64, 0.63, 18.01, 12.16), sd = c(14.9, 10.2,
    16.3, 11, 9.4, 11.4, 10.4, 17.6)), .Names = c("school", "estimate",
    "sd"), class = "data.frame", row.names = c("1", "2", "3", "4",
    "5", "6", "7", "8"))

dat <- list(J = nrow(schools),
    y = schools$estimate,
    sigma.y = schools$sd)
bugs.model <- function(){
       for (j in 1:J){
         y[j] ~ dnorm (theta[j], tau.y[j])
         theta[j] ~ dnorm (mu.theta, tau.theta)
         tau.y[j] <- pow(sigma.y[j], -2)
       }
       mu.theta ~ dnorm (0.0, 1.0E-6)
       tau.theta <- pow(sigma.theta, -2)
       sigma.theta ~ dunif (0, 1000)
     }
param <- c("mu.theta", "sigma.theta")

sim1 <- bugs.fit(dat, param, bugs.model,
    program="openbugs", n.iter=100, n.thin=1, seed=1)

cl <- makePSOCKcluster(3)
sim2 <- bugs.parfit(cl, dat, param, bugs.model,
    program="openbugs", n.iter=100, n.thin=1, seed=1:3)
sim3 <- bugs.parfit(cl, dat, param, bugs.model, working.directory = getwd(),
    program="openbugs", n.iter=100, n.thin=1, seed=1:3)
stopCluster(cl)

lapply(sim1, head) # OK
lapply(sim2, head) # OK
lapply(sim3, head) # not OK