Hi team,
Can anyone please help here with the explanation of the below code chunk in the proposal function of MCMC -
if (runif(1) < probab){
chain[i+1,] = proposal
}else{
chain[i+1,] = chain[I,]
}
- Why is the runif() function used here? Is there any theory to support this?
- Can we use any other function in place of runif() function?
I really appreciate any help you can provide.
Complete reference for the code : Metropolis-Hastings MCMC in R
This is part of the Metropolis algorithm, see Section 11.2 of Bayesian Data Analysis (page 282 in the online version here) for a more complete background
1 Like
Hi @andrjohns,
Going through the book only helped me know the advantages of Uniform Distribution but it did not seem to answer the question, why compare with a value less than 1 and greater than 0 generated by Uniform distribution and accept or reject the acceptance ratio for the candidate in the MetropolisāHastings algorithm?
@Taranpreet_Kaur the intuitions behind the randomness in the metropolis proposal acceptance/rejection rule is in the core of a lot of MCMC samplers.
Try this book https://www.mcmchandbook.net/ it might help you.