Hi all:
I am trying to use the randgamma function from
http://research.microsoft.com/enus/um/people/minka/software/lightspeed/
According to the help for this function:
Gamma(a) has density function p(x) = x^(a1)*exp(x)/gamma(a).
Now it seems that, according to
http://en.wikipedia.org/wiki/Gamma_distribution
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^(a1)*exp(x/theta) / (gamma(a)*theta^a);
Finally, a chisquare distribution with degrees of freedom k:
p(k) = x^(k/21)*exp(x/2) / (gamma(k/2)*2^(k/2));
I am trying to draw from a chisquare distribution using randgamma. Specifically, my understanding is that if I let
y = x/2;
and
a = k/2;
I should be able to draw from the corresponding randgamma(a) distribution; in other words:
chivalues = 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^(a1)*exp(y)/gamma(a).
p(y) = (x/2)^(a1)*exp(x/2)/gamma(a).
p(y) = (x)^(a1)*exp(x/2) / (gamma(a)*2^(a1))
p(y) = 2 * (x)^(a1)*exp(x/2) / (gamma(a)*2^a)
p(y) = 2 * x^(k/21)*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
Misha
