Gamma distribution & Markov chain Monte Carlo
- From: Maniaoh <n.hoainam@xxxxxxxxx>
- Date: Wed, 16 Jul 2008 23:23:15 -0700 (PDT)
Hi guys,
I code a small piece to generate variates from Gamma distribution with
Markov chain Monte Carlo as shown below. The appeared results,
however, using 'hist(vari)' command does not looks like it follows
Gamma distribution at all. (I compare it with 'gamrnd' provided in
Matlab.) None of Metropolis - Hastings or Metropolis method works.
Please kindly provide me some hints about this problem, I'm totally
lost.
Thanks in advance. Any comment is highly appreciated.
Iaoh.
--------------------
clear all
% number of iterations
n = 5000;
% burn-in rounds
burnin = 2000;
% preallocate the array
vari = zeros(1, n);
str = 'x^(a - 1)*exp(-b*x)'; % gamma distribution
gamDist = inline(str, 'x', 'a', 'b');
a = 1;
b = 1;
str = 'exp(-0.5*((x-mu)/sig)^2)';
norm = inline(str, 'x', 'mu', 'sig');
sig = 1;
vari(1) = randn(1); % initial value
for index = 2:n
% normal distribution is used as proposal distribution
y = vari(index - 1) + randn(1)*sig;
% draw u from normal distribution
u = randn(1);
% calculate accepting factor alpha
% by Metropolis - Hastings method
alpha = min(1, (gamDist(y, a, b))*norm(vari(index - 1), y,
sig)/...
((gamDist(vari(index - 1), a, b))*norm(y, vari(index -
1), sig)));
% by Metropolis-only method
% alpha = min(1, (gamDist(y, a, b))/(gamDist(vari(index - 1), a,
b)));
if u <= alpha
vari(index) = y;
else
vari(index) = vari(index - 1);
end
end
% remove burn-in elements
vari = vari(burnin:n);
hist(vari);
.
- Follow-Ups:
- Re: Gamma distribution & Markov chain Monte Carlo
- From: lscharen
- Re: Gamma distribution & Markov chain Monte Carlo
- From: Herman Rubin
- Re: Gamma distribution & Markov chain Monte Carlo
- Prev by Date: Re: Estimate if two bivariate sets are statistically different
- Next by Date: Re: DO NOT BELIEVE IN WHAT Jack Tomsky say
- Previous by thread: Re: paypal wholesale Diesel shirt Bape jeans(paypal accept)(www super-
- Next by thread: Re: Gamma distribution & Markov chain Monte Carlo
- Index(es):
Relevant Pages
|
Loading