From: Francesco Bianchi on
Hi,
I am using the function:

function r = drchrnd(a,m)
r = gamrnd(repmat(a,m,1),1,m,length(a));
r = r(:,1:end-1) ./ repmat(sum(r,2),1,length(a)-1);

to make draws from a Dirichlet distribution (I found it on the matlab web-site). The function works well when "a" is a 2 element vector, but it seems to get the mode wrong when "a" has a larger size.
Mean and variance turn out to be right, though.
Best,

Francesco
From: Roger Stafford on
"Francesco Bianchi" <francesco.bianchi(a)duke.edu> wrote in message <i274gc$emp$1(a)fred.mathworks.com>...
> Hi,
> I am using the function:
>
> function r = drchrnd(a,m)
> r = gamrnd(repmat(a,m,1),1,m,length(a));
> r = r(:,1:end-1) ./ repmat(sum(r,2),1,length(a)-1);
>
> to make draws from a Dirichlet distribution (I found it on the matlab web-site). The function works well when "a" is a 2 element vector, but it seems to get the mode wrong when "a" has a larger size.
> Mean and variance turn out to be right, though.
> Best,
>
> Francesco
- - - - - - - - -
I don't spot anything wrong with the code, provided you enter a as a row vector. What do you mean by "get the mode wrong"?

Roger Stafford