Set seed for Bayesian Network in R

44 Views Asked by At

I was performing a Bayesian network meta-analysis and I encountered difficulties in setting the seed for a sub-analysis.

In particular, while using the gemtc package, I was able to set the seed in all the analyses with this code:

set.seed(9999)
model.re <- mtc.model(network, type = "consistency", factor = 2.5, n.chain = 4, likelihood="binom", link="logit", linearModel="random", om.scale=5, hy.prior=mtc.hy.prior("std.dev", "dunif", 0, 5))
summary(model.re)
seeds <- sample.int(4, n=.Machine$integer.max)
model.re$inits <- mapply(c, model.re$inits, list(
  list(.RNG.name="base::Wichmann-Hill",.RNG.seed=seeds[1]),
  list(.RNG.name="base::Marsaglia-Multicarry",.RNG.seed=seeds[2]),
  list(.RNG.name="base::Super-Duper",.RNG.seed=seeds[3]),
  list(.RNG.name="base::Mersenne-Twister",.RNG.seed=seeds[4])),SIMPLIFY=FALSE)
result.re <- mtc.run(model.re, sampler="JAGS", n.adapt=50000, n.iter=100000, thin=1)
summary(result.re)

However, when trying to set it for the node-split analysis it fails when running this code:

set.seed(9999)
result.ns <- mtc.nodesplit(network, factor = 2.5, n.chain = 4, likelihood="binom", link="logit", linearModel='random', n.adapt=50000, n.iter=100000, thin=10, om.scale=5, hy.prior=mtc.hy.prior("std.dev", "dunif", 0, 5))
mtc.nodesplit.comparisons(network)
summary.ns <- summary(result.ns)
plot(summary.ns, digits=4, xlim=c(-1.609438,1.609438))
summary.ns

I don't get why is it possible, maybe something in the original code? Should I try to implement directly through JAGS?

Many thanks in advance.

0

There are 0 best solutions below