Take the 2-minute tour ×

I have been trying to learn the Bayesian simulation based methods of posterior approximation. Although the theories are now quite clear but I am seeking for some examples with R codes so that I can practice and implement to my own work.

I am particularly looking for the examples with R codes of the non-iterative and iterative Monte Carlo methods. Mainly-

  1. Importance sampling
  2. Rejection sampling
  3. Metropolis algorithm
  4. Metropolis-Hastings algorithm
  5. Gibbs sampler

So, is it possible to find examples with R codes of these methods of simulation somewhere collectively? I mean it is a kind of heuristic learning, so basically I need some tutorial or some blog or website where the examples are properly described with corresponding R codes.

Edit: I am sorry I forgot to mention, I was actually looking for creating functions in R for these sampling methods to know the basic of these algorithms. Not looking for any packaged software.

share|improve this question
Of possible interest: Good summaries (reviews, books) on various applications of Markov chain Monte Carlo (MCMC)?. Another popular book on MCMC methods is Monte Carlo Statistical Methods. –  user10525 Nov 13 '12 at 16:45

1 Answer 1

up vote 3 down vote accepted

Online information would suggest

Christian Robert, George Casella (2009). Introducing Monte Carlo Methods with R. Springer-Verlag, New York.

would at least be a start and the code is available in the mcsm package here.

Perhaps someone who has actually read it might be able to provide further comments.

share|improve this answer
Thank you for the reference, but is it possible to learn how to program the algorithms myself? I mean I am interested to not use any package but to learn how to write the very basic functions for these algorithms. –  Blain Waan Nov 13 '12 at 16:43
Again, I do not know, but the online material suggested that - perhaps @Xi'an will be kind enough to answer this query. –  phaneron Nov 13 '12 at 18:25
@BlainWaan: In our book, we use the R language to teach how to program the algorithms. The package is just there to avoid the user re-typing every example. I am not trying to (over)sell the book, however I use it in class to get the students to learn Monte Carlo and MCMC. If you look at the book online, you will see we cover exactly the program you set in your question... –  Xi'an Nov 14 '12 at 10:04
@phaneron: thanks! –  Xi'an Nov 14 '12 at 10:04
phaneron Thanks! It was truly useful. Very nice book, very well written. Thanks @Xi'an too. –  Blain Waan Nov 15 '12 at 17:49

Your Answer


