From c0c0d48fed054595ee6ce41043065faf17a291e8 Mon Sep 17 00:00:00 2001 From: sebastien Date: Mon, 21 Dec 2009 11:08:59 +0000 Subject: [PATCH] Fix gamrnd.m: for big integer values of parameter a, the gaussian approximation was incorrect (closes #67) git-svn-id: https://www.dynare.org/svn/dynare/trunk@3281 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/missing/stats/gamrnd.m | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/matlab/missing/stats/gamrnd.m b/matlab/missing/stats/gamrnd.m index e1139944c..694a42cf5 100644 --- a/matlab/missing/stats/gamrnd.m +++ b/matlab/missing/stats/gamrnd.m @@ -8,7 +8,7 @@ function rnd = gamrnd(a,b,method) % % OUTPUT % rnd [double] n*1 vector of independent variates from the gamma(a,b) distribution. -% rnd(i) is gamma distributed with variance a(i)b(i) and variance a(i)b(i)^2. +% rnd(i) is gamma distributed with mean a(i)b(i) and variance a(i)b(i)^2. % % ALGORITHMS % Described in Bauwens, Lubrano and Richard (1999, page 316) and Devroye (1986, chapter 9). @@ -85,7 +85,7 @@ if number_of_integer_a end if number_of_big_a % Gaussian approximation. - rnd(integer_idx(big_idx)) = .25*( randn(number_of_big_a,1) + sqrt(4*a(integer_idx(big_idx))-1) ).^2 ; + rnd(integer_idx(big_idx)) = sqrt(a(integer_idx(big_idx))).* b(integer_idx(big_idx)) .* randn(number_of_big_a, 1) + a(integer_idx(big_idx)) .* b(integer_idx(big_idx)); end end @@ -130,8 +130,6 @@ if number_of_double_a end - - function gamma_variates = weibull_rejection_algorithm(a,b) nn = length(a); mm = nn; @@ -402,5 +400,3 @@ while mm mm = length(index); end gamma_variates = X.*b; - -