A toy program to generate a sequence of random numbers distributed according to ANY probability distribution using the Metropolis-Hastings algorithm.

The probability distribution of interest is myPDF(x) It does not need to be normalized. It is hardcoded. Easy to change.

The user needs to supply a few things.

First: A pdf that is used to move in the sequence of random numbers from x to y. This is the so called "proposal distribution" P(y|x). Note: this is NOT the probability of the nth random number being y if the nth-1 is x. But it is related to it..... In principle P(y|x) can be ANY function as long as it is non-zero in the domain of validity of myPDF. The proposal function is of the Metropolis type, ie, P(y|x) = P(x|y) It is hardcoded as proposal(x) and returns y Note that the returned value is still just a "proposal" so it can be accepted or rejected

Second: An initial value of x.
It can be anything but it must have myPDF(x) > 0 It probably makes sense for this to be somewhere in the bulk of the distribution of interest.

Third: The number of members of the chain to generate (n)

Fourth: The number of initial members of the chain to ignore (the so called burn-in, nBurn)

To visualize the chain, we fill a histogram of members of the chain. The parameters of the histogram are hardcoded.