# sampling from normal distribution using MCMC doesn't seem correct [closed]

I'm trying to sample from the normal distribution with a mean of .5 (like flipping a coin) and an arbitrary standard deviation using a markov chain (sequence of numbers where each number is dependent on the previous number of the sequence).

since this is a normal distribution under a markov chain, I expect the sampled values to fluctuate between 0 and 1 but mostly around .5 (like a random walk). I expect a result similar to this:

but when I try to do it my result looks like this:

I don't know why in that example the MCMC iteration never gets negative thetas or thetas greater than 1. all my plots are never contained between 0 and 1. if Normal(proposed_theta) outputs a value greater than 1 or is negative that is very problematic.

## closed as off-topic by Peter Flom♦Apr 22 at 11:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• This is going to require people to watch the video. Can you make this question self-contained? I suspect there would be an on-topic question here. – gung Apr 22 at 14:49

What's missing in what you are doing is an acceptance step that accepts a proposal based on the normal density $$f(x_i)$$ at the current state of the chain $$x_i$$ and that at the proposed value $$x_{i+1}'$$. This could be based on using an acceptance probability $$\min(1, f(x_{i+1}')/f(x_{i}))$$ (move to the proposal that probability, make the previous value the next one otherwise), if you want to use Metropolis Hastings.