1
$\begingroup$

My breath was taken away by this. I tried to run my JAGS model with different number burn-in samples but it still takes the same amout of time!!

n.iter    n.burnin    time   saved iterations per chain
 2000         1000     66s                         1000
 5000         4000     64s                         1000
20000        19000     62s                         1000

n.chains was 2 and n.thin was 1. So in each of the 3 model runs, I had different burn-in period, but the same second stage (n.iter - n.burnin, i.e. 1000 iterations per chain). All 3 models run for the same period of time!!! Does this mean that the burn-in phase takes zero time?

This is really a strange result, doesn't correspond to how I supposed the MCMC works. I thought that the burn-in phase is exactly the same computation process as the second stage, with the only difference that the samples are discarded.

I have used R2jags::jags function to run JAGS.

$\endgroup$
1
$\begingroup$

That's weird. Are you sure it's not a problem with your timer?

I prefer using rjags or dclone packages, but running this R2Jags example code:

library(R2jags)
# data
J <- 8.0
y <- c(28.4,7.9,-2.8,6.8,-0.6,0.6,18.0,12.2)
sd <- c(14.9,10.2,16.3,11.0,9.4,11.4,10.4,17.6)


jags.data <- list("y","sd","J")
jags.params <- c("mu","sigma","theta")
jags.inits <- function(){
  list("mu"=rnorm(1),"sigma"=runif(1),"theta"=rnorm(J))
}


schoolsmodel <- function() {
  for (j in 1:J){   # J=8, the number of schools
    y[j] ~ dnorm (theta[j], tau.y[j]) # data model:  the likelihood
    tau.y[j] <- pow(sd[j], -2)  # tau = 1/sigma^2
  }
  for (j in 1:J){
    theta[j] ~ dnorm (mu, tau)  # hierarchical model for theta
  }
  tau <- pow(sigma, -2)   # tau = 1/sigma^2
  mu ~ dnorm (0.0, 1.0E-6)# noninformative prior on mu
  sigma ~ dunif (0, 1000) # noninformative prior on sigma
}

a <- list()
a[[1]] <- system.time(jagsfit <- jags(data=jags.data,
inits=jags.inits, jags.params, n.chains = 2,
n.iter = 2000, n.burnin = 1000, n.thin = 1, model.file=schoolsmodel))
a[[2]] <- system.time(jagsfit <- jags(data=jags.data,
inits=jags.inits, jags.params, n.chains = 2, 
n.iter = 5000, n.burnin = 4000, n.thin = 1, model.file=schoolsmodel))
a[[3]] <- system.time(jagsfit <- jags(data=jags.data,
inits=jags.inits, jags.params, n.chains = 2, 
n.iter = 20000, n.burnin = 19000, n.thin = 1, model.file=schoolsmodel))
a[[4]] <- system.time(jagsfit <- jags(data=jags.data,
inits=jags.inits, jags.params, n.chains = 2, 
n.iter = 200000, n.burnin = 200000-1000, n.thin = 1, model.file=schoolsmodel))

Gave me the following results:

>   a
    [[1]]
 user  system elapsed 
0.242   0.000   0.244 

    [[2]]
 user  system elapsed 
0.272   0.000   0.274 

    [[3]]
 user  system elapsed 
0.541   0.000   0.544 

    [[4]]
 user  system elapsed 
3.732   0.005   3.746 

Which indicates everything is as expected.

$\endgroup$
  • $\begingroup$ wow, that's strange! You have two progress bars, first one for burn-in and the second one for second stage, but I am completely missing the burn-in one! Despite of the fact that burn-in is set! Don't know what is going on. $\endgroup$ – Curious Feb 6 '14 at 9:43
  • $\begingroup$ This also happen in the code above? Might be a problem with R2Jags not passing the burn-in to Jags? What about using package rjags? $\endgroup$ – random_user Feb 6 '14 at 12:43
  • $\begingroup$ Nope, in your code I get two progress bars, but not in my code! $\endgroup$ – Curious Feb 6 '14 at 12:44
  • $\begingroup$ Odd indeed, as the manual states If n.burnin is 0, jags() will run 100 iterations for adaption., then even with no burn.in set, you should get the progress bar. So I don't know why you don't see the burn-in progress bar. $\endgroup$ – random_user Feb 6 '14 at 12:52
  • 1
    $\begingroup$ I examined the issue in detail and got the answer! If you just change dunif to dgamma(0.01, 0.01), you will start to observe the problem :-) See stats.stackexchange.com/a/90492 $\endgroup$ – Curious Mar 18 '14 at 20:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.