# Reference on examples with R codes for Bayesian simulation based methods of posterior approximation

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.

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.

• 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. Nov 13, 2012 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. Nov 13, 2012 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... Nov 14, 2012 at 10:04
• @Xi'an Thanks a lot. I'll definitely appreciate such a book. :) Nov 14, 2012 at 16:03
• phaneron Thanks! It was truly useful. Very nice book, very well written. Thanks @Xi'an too. Nov 15, 2012 at 17:49