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

New to MATLAB?

Thread Subject:
draw from chi2 using randgamma lightspeed question

Subject: draw from chi2 using randgamma lightspeed question

From: Misha Koshelev

Date: 19 Jun, 2009 20:19:03

Message: 1 of 1

Hi all:

I am trying to use the randgamma function from

According to the help for this function:
  Gamma(a) has density function p(x) = x^(a-1)*exp(-x)/gamma(a).

Now it seems that, according to
a Gamma distribution can be defined in terms of two parameters a and theta, such that
Gamma(a,theta) has density function
p(a,theta) = x^(a-1)*exp(-x/theta) / (gamma(a)*theta^a);

Finally, a chi-square distribution with degrees of freedom k:
p(k) = x^(k/2-1)*exp(-x/2) / (gamma(k/2)*2^(k/2));

I am trying to draw from a chi-square distribution using randgamma. Specifically, my understanding is that if I let
y = x/2;
a = k/2;
I should be able to draw from the corresponding randgamma(a) distribution; in other words:
chi-values = 2*randgamma(k/2);

However, based on the randgamma documentation of the pdf, there is a missing factor of 2 in the denominator. Notably:
p(y) = y^(a-1)*exp(-y)/gamma(a).
p(y) = (x/2)^(a-1)*exp(-x/2)/gamma(a).
p(y) = (x)^(a-1)*exp(-x/2) / (gamma(a)*2^(a-1))
p(y) = 2 * (x)^(a-1)*exp(-x/2) / (gamma(a)*2^a)
p(y) = 2 * x^(k/2-1)*exp(-x/2) / (gamma(k/2)*2^(k/2))

Now the integral from -Inf to Inf of a pdf must be equal to 1, so I am a little confused as to this factor of 2. Am I missing something simple?

Thank you

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