3
$\begingroup$

I am trying to use Bayesian model averaging for variable selection with a large number of variables. In R, the BMS package allows to apply the method, with the option of using MCMC sampler (Metropolis Hastings algorithm) when the number of covariates is large.

Here is a sample code:

 data(datafls)
 fls1 = bms(datafls, burn = 50000, iter=100000, g = "BRIC", mprior = "uniform", nmodel = 2000, mcmc="bd", user.int=F)
 result = coef(fls1)

However, if you run the same code twice, the results (i.e. the posterior probabilities) would be completely different. Does anyone know how to tune the code, so that the results are consistent for every run?

Thank you,

$\endgroup$

1 Answer 1

3
$\begingroup$

This is an artifact of the stochasticity of MCMC sampling. The best you can do is set a specific seed before each run, using set.seed():

set.seed(123)
fls1 = bms(datafls, burn = 50000, iter=100000, g = "BRIC", mprior = "uniform", nmodel = 2000, mcmc="bd", user.int=F)

set.seed(123)
fls2 = bms(datafls, burn = 50000, iter=100000, g = "BRIC", mprior = "uniform", nmodel = 2000, mcmc="bd", user.int=F)

This causes the initial conditions of R's random number generator to be the same before you run your samplers, so the results of fls1 and fls2 will be the same.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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