Member-only story

Create a Monte Carlo simulation Gibbs sampler in R

Crystal X
4 min readDec 18, 2024

--

In my previous post I discussed how to create a Monte Carlo Gibbs sampler in Python, and that post can be read here:- https://medium.com/@tracyrenee61/create-a-monte-carlo-simulation-gibbs-sampler-in-python-e1f0b05663b6

In this post I intend to discuss how to create the same Gibbs sampler, but I will have written the code in R instead of Python.

Python is a gene ral purpose programming language, while R was developed expressly for statistical work.

One good thing about R is the fact that many of the functions are built into the language, so in many cases there is no need to import libraries. Therefore, in this script that I have written, no libraries need to be imported.

The program has been written using MyCompiler, which is an online R compiler. I have chosen this compiler because it allows me to visualise the data, something that many online compilers don’t have the capacity for.

The first thing that I did was to define and initialise the variables that would be used in the program:-

I then entered the code for the Gibbs sampler.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet