Re: Gamma distribution & Markov chain Monte Carlo
- From: lscharen@xxxxxxxxx
- Date: Fri, 18 Jul 2008 09:23:00 -0700 (PDT)
On Jul 18, 2:59 am, Maniaoh <n.hoai...@xxxxxxxxx> wrote:
Hi Lucas,
Just as you say, a proposal of normal distribution does nothing
harmful to the target distribution if it generates value less than
zero. It can be confirmed through explicit expression of alpha.
Nevertheless, when I allow normal distribution to generate less-than-
zero values, the target distribution does not seem right. When I draw
histogram, on the negative side of axis, some values of y (target) are
generated.
You exactly state what I did, even the code :), I took a guard and
therefore the proposal normal distribution became a truncated one. In
this case, the result is better, i.e., histogram. Do you have any
comment on this?
If you are still seeing negative values of y then there is something
wrong in your code. I'm sure truncating y to be positive does improve
the histograms, but that doesn't mean it's correct. :)
I implemented your code myself as follows. It appears to work fine --
no negative y values and a histogram of 10,000 samples is a pretty
good looking gamma. Use this as a reference to check your own code.
function s = gamma_mcmc(n)
s = zeros(1,n);
gampdf = @(x,a,b) x.^(a-1) * exp(-b*x) .* (x>=0);
normpdf = @(x,mu,sig) exp(-0.5*((x-mu)/sig).^2);
a = 1;
b = 1;
sig = 1;
% Initialize chain at the mean of the gamma distribution
x = a * b;
for i = 1:n,
% Generate a proposal from a normal distribution
x_star = x + sig .* randn;
% Calculate the M-H acceptance
q_x_given_x_star = normpdf( x, x_star, sig );
q_x_star_given_x = normpdf( x_star, x, sig );
p_x = gampdf( x, a, b );
p_x_star = gampdf( x_star, a, b );
alpha = (p_x_star * q_x_given_x_star) / (p_x * q_x_star_given_x );
if rand <= alpha
x = x_star;
end
s(i) = x;
end
.
- Follow-Ups:
- Re: Gamma distribution & Markov chain Monte Carlo
- From: Maniaoh
- Re: Gamma distribution & Markov chain Monte Carlo
- References:
- Gamma distribution & Markov chain Monte Carlo
- From: Maniaoh
- Re: Gamma distribution & Markov chain Monte Carlo
- From: lscharen
- Re: Gamma distribution & Markov chain Monte Carlo
- From: Maniaoh
- Re: Gamma distribution & Markov chain Monte Carlo
- From: lscharen
- Re: Gamma distribution & Markov chain Monte Carlo
- From: Maniaoh
- Gamma distribution & Markov chain Monte Carlo
- Prev by Date: Re: DO NOT BELIEVE IN WHAT Jack Tomsky say
- Next by Date: Re: only significant with interaction
- Previous by thread: Re: Gamma distribution & Markov chain Monte Carlo
- Next by thread: Re: Gamma distribution & Markov chain Monte Carlo
- Index(es):
Relevant Pages
|