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:

enter image description here

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

enter image description here

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.

  • $\begingroup$ 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. $\endgroup$ – 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.

  • $\begingroup$ the problem I ran into is if f(x_i+1)/f(x_i) is a negative value then the new proposed x_i+1 will get accepted it won't be bounded between 0 and 1. $\endgroup$ – Aystealthy Apr 22 at 15:29
  • $\begingroup$ A probability density function is never negative, so that should never be a. issue. Perhaps you used the log pdf by accident? Forming the difference on the log scale may be useful for numerical stability, but then you need to change everything else accordingly. $\endgroup$ – Björn Apr 22 at 15:34
  • $\begingroup$ in the 1st picture above, Normal with mean .836 outputs .820. does that mean there is an 82% chance that the sampled values will be less than .836? $\endgroup$ – Aystealthy Apr 22 at 16:19
  • $\begingroup$ Unsure what you mean. You should be using the pdf, not the cdf. $\endgroup$ – Björn Apr 22 at 16:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.