Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: zeros in the Gamma distribution.


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: zeros in the Gamma distribution.
Date   Thu, 8 Apr 2010 14:28:42 +0100

I agree with Maarten's main point: Precision will bite here because the smallest possible positive value cannot be arbitrarily small. Using -double- will ease this problem but cannot remove it absolutely. 

Although Sun Samn tells us very little about what is being done, it seems quite likely that a change of measurement units might help (e.g. working in mg rather than kg) and/or that operations should be carried out on a transformed scale, e.g. work with logarithms and simulate gamma distributions rather than vice versa. 

Nick 
n.j.cox@durham.ac.uk 

Maarten buis

--- On Thu, 8/4/10, sun samn wrote:
>    As we all know, the random numbers from Gamma
> distributions should be positive; but when I use 'rgamma' to
> generate 100 numbers, it has 7 zeros, why is that? Is this
> reasonable? is there any way to get rid of these zeros? 
>    You know ,I need to take log of these numbers, the
> zeros are really bothering me.

It means you are trying to use a too extreme distribution. 
Basically the numbers become so small that a computer cannot
distinguish them from zero. Things become better when you
create the variable as doubles, but it still finds a substantial
number of zeros in the most extreme distribution. But looking at
these distributions you can see that they cannot possible serve
any practical purpose: to all intends and purposes they are so
extreme that in a real data situaton there would be no way of
distinguishing this distribution form a spike at zero and a small 
scattering of other values.

*-------- example using floats ------------
clear
set obs 10000
gen x1 = rgamma(1,1)
count if x1 == 0
gen x2 = rgamma(.1,1)
count if x2 == 0
gen x3 = rgamma(.01,1)
count if x3 == 0
gen x4 = rgamma(.001,1)
count if x4 == 0
*------------ end example ------------------

*----------- example using doubles ------------
clear
set obs 10000
gen double x1 = rgamma(1,1)
count if x1 == 0
gen double x2 = rgamma(.1,1)
count if x2 == 0
gen double x3 = rgamma(.01,1)
count if x3 == 0
gen double x4 = rgamma(.001,1)
count if x4 == 0
*-------------- end example -----------------


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index