Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Dirichlet distribution

Subject: Dirichlet distribution

From: Francesco Bianchi

Date: 21 Jul, 2010 15:42:04

Message: 1 of 2

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

Subject: Dirichlet distribution

From: Roger Stafford

Date: 21 Jul, 2010 20:09:04

Message: 2 of 2

"Francesco Bianchi" <francesco.bianchi@duke.edu> wrote in message <i274gc$emp$1@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us