# First iteration in MCMC coda chain is different from initial values

I have my jags output object. In order to understand how MCMC coda chains work, I tried to see if first iteration in each MCMC chain is equal to the initial values supplied. And it is different! The initial value is not there! Is it an error?

Note that I specified burnin = 0 for this purpose.

How I ran jags:

inits = function () { list(
alpha = rnorm(no_crit, 0, 10000),
beta = rnorm(no_crit, 0, 10000)
,eps_tau = 7.9
,gamma_tau = 3.1
,delta_tau = 213
)
}

params = c("alpha", "beta", "eps_tau", "gamma_tau", "delta_tau")

ni <- 5000
nt <- 8
nb <- 0
nc <- 3

out <- R2jags::jags(win.data, inits, params, "model.txt",
nc, ni, nb, nt,
working.directory = paste(getwd(), "/tmp_bugs/", sep = "")
)


After the jags computation finished, I dumped the first iteration from each MCMC coda chain:

> mm = as.mcmc(out)
> mm[1, c("delta_tau", "eps_tau")]
> mm[1, c("delta_tau", "eps_tau")]
[[1]]
delta_tau      eps_tau
4426.7716020    0.4825011

[[2]]
delta_tau      eps_tau
4811.3174529    0.5240721

[[3]]
delta_tau      eps_tau
4406.2672016    0.5351576


As you can see, the first iteration in all these chains is different from what I supplied as initial values (eps_tau = 7.9, delta_tau = 213).

-

I haven't dug into the JAGS source code, but often people consider the initial values to be iteration 0, and for iteration 1 to be the result after a single pass through the Gibbs sampler.

Also, if there are any Metropolis steps, there is likely to be a short adaptation phase before iteration 1 irrespective of the burn-in setting.

-
Thank you. What is Metropolis steps and how do I realize if theay are present in WinBUGS/OpenBUGS/jags? – Curious Oct 30 '12 at 23:42
Metropolis steps are a part of the Markov Chain Monte Carlo algorithm; see Wikipedia. – Jack Tanner Nov 30 '12 at 3:29
@JackTanner the "GS" in 'BUGS' and 'JAGS' stands for Gibbs Sampling. If by 'Metropolis step' you mean the part in Metropolis-Hastings where the proposed move may or may not be accepted, Gibbs Sampling has no Metropolis step since its $\alpha$ ratio is (by design) always exactly 1. – Glen_b Aug 28 '13 at 0:13

First, JAGS doesn't do burn-in clipping - R2jags does something, but I don't know what that is. Second, adaptation (see the JAGS user manual) may affect initial values. Third, even if you turn off adaptation, R2jags used to have a bug with initial values. Better to use rjags instead.

-
what do you mean by "jags doesn't do burn-in clipping"? Jags takes burnin parameter, and I'm not sure now but I think that the number of output iterations should confirm, that clipping is performed. – Curious Nov 30 '12 at 19:04
JAGS does not have a burn-in parameter that I know of; it does have an adaptation parameter (called n.adapt in rjags). – Jack Tanner Nov 30 '12 at 19:14