0

To Clarify i am trying to generate a random variable from a gamma pdf

If $\Delta X$ indicates a random increment and it is said that $\Delta X$ follows a Gamma distribution.

What would that mean exactly? How would you be able to get random variables from the Gamma distribution?

So far I understood the following, but am guessing this might be wrong:

$$ X\sim \Gamma(\alpha,\beta)\equiv\operatorname{\Gamma}(\alpha,\beta)$$

This means $X$ follows a Gamma distribution so $\Delta X$ is a kind of sum of the different values $X$ takes at every iteration

$$g(x;\alpha, \beta) = \frac{\beta^\alpha x^{\alpha-1}e^{-x\beta}}{\Gamma(\alpha)}, \text{ for } x\geqslant 0\text{ and } \alpha,\beta>0 $$

so $X$ is represented by $x$ in the Gamma pdf, meaning I should put the value of $X$ for $x$ when computing the value of $X$ from the Gamma pdf?

https://en.wikipedia.org/wiki/Gamma_distribution

Math1000
  • 38,041
AnarKi
  • 267
  • What do you call "computing the value of X from the Gamma pdf"? One does not "compute the value" of a random variable... – Did Jul 24 '15 at 15:04
  • @Did Sure you can! Given $\omega\in\Omega$, one can compute the value of e.g. $X(\omega)$ (granted this is only possible if the function $X:\Omega\to\mathbb R$ is defined explicitly instead of in terms of its distribution). – Math1000 Jul 24 '15 at 15:52
  • @Math1000 Thanks for your comment. Is it related to the present page? – Did Jul 24 '15 at 15:53
  • I was being facetious re: "One does not "compute the value" of a random variable" :) – Math1000 Jul 24 '15 at 15:57
  • @Math1000 And misleading to the OP, I am afraid. – Did Jul 24 '15 at 16:01
  • @OP For your interest, the two current first sentences of your post "To Clarify i am trying to generate a random variable from a gamma pdf" and "If ΔX indicates a random increment and it is said that ΔX follows a Gamma distribution" contradict each other. The latter points at the simulation of the increments of a process while the former restricts the question to the simulation of a single random variable. Personally, I would bet on the latter (the process version). Providing the source of your question would allow to settle this. – Did Jul 24 '15 at 16:05
  • actually ΔX would be the increment, so the need would be to generate random variables following the gamma pdf, these variables would then summed up – AnarKi Jul 24 '15 at 16:08
  • @Did Sometimes I forget that text is not often a good medium for sarcasm ;) – Math1000 Jul 24 '15 at 17:06
  • @AnarKi So, definitely the process version. Since you accepted an answer dealing with the single random variable version, you can deduce the former from the latter. How? – Did Jul 24 '15 at 17:34
  • 1
    @Math1000 No problem, I might be too slow... – Did Jul 24 '15 at 17:35
  • @Did again it would be the other way around generate a random variable that follows the gamma pdf and then generate another random variable the same for as many iterations as needed, or maybe i'm misunderstanding your question – AnarKi Jul 24 '15 at 17:55

2 Answers2

3

It sounds like you want to generate gamma-distributed random variables. If you want to write the code yourself, the way I know how is using the acceptance-rejection method by first generating an exponentially-distributed RV. An exponential random variable $G$ with pdf $\lambda \mathrm e^{-\lambda g}$ may be generated by first generating a uniform(0,1) random variable $U$ and applying the inverse transformation $$ G = -\frac{1}{\lambda}\log(1-U). $$ To generate a $gamma(\alpha,\beta)$-ditributed random variable, choose $\lambda = \frac{\alpha}{\beta}$ above and then use the acceptance-rejection method.

OTOH most scientific software includes these methods. E.g. MATLAB's gaminv(p,a,b) could be used where $p$ is a uniform(0,1), $a = \alpha$ and $b = \frac{1}{\beta}$ (MATLAB uses the "other" version of the pdf you've given). For example if you want to generate $1000$ gamma(2,3) random variables:

a=2;
b=1/3;
n=1000;
u=rand(n,1);
g=gaminv(u,a,b);
bcf
  • 3,238
  • 3
  • 23
  • 40
0

If $F$ is the pdf of the Gamma distribution with the correct parameters then for all real $x$, $$\Pr[\Delta X < x] = F(x).$$ This defines the distribution of $\Delta X$ completely.

Yuval Filmus
  • 57,953
  • Thank you for the answer but I dont know if i understood the answer, how do you define x ? ∆X should be random so should there be a random process for defining x, i am sorry if i dont get it, could you explain in more depth ? – AnarKi Jul 24 '15 at 14:55
  • I'm not defining $x$. The equation is true for all $x$. For example, the probability that $\Delta X$ is at most $10$ is $F(10)$. – Yuval Filmus Jul 24 '15 at 14:55