[R] many zeroes in rgamma ... what's going on?
Duncan Murdoch
murdoch at stats.uwo.ca
Mon Nov 19 01:14:34 CET 2007
On 18/11/2007 4:15 PM, Gregory Gentlemen wrote:
> Dear Dr. Dalgaard,
>
> Thank you for your insight! In fact, I did read the example documentation, however, it pretty much told me the same thing that my little simulation did: there is ALOT of point mass at zero.
>
> Is there any fix to this problem? Seeing that rgamma won't work accurately, if I wanted to plot a density of an inverse gamma distribution with small scale and shape parameters, how would I do so?
Getting the density of the gamma should be simply a matter of calling
dgamma, perhaps with log=TRUE set to avoid over/underflow. Use
standard change of variable methods (Jacobians, etc.) to get the density
of your transformed version.
Duncan Murdoch
>
> Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote: Gregory Gentlemen wrote:
>> Hello fellow R users,
>>
>> I wanted to view the density on the standard deviation scale of a gamma(0.001, 0.001) prior for the precision. I did this as seen in the code below and found that for some reason rgamma is giving many values equal to zero, which is strange since a gamma distribution is continuous. What is going on here?
>>
>> Thanks for any help in advance.
>> Greg
>>
> That sort of shape parameter gives a distribution with most of its mass
> squashed against the y axis, so random numbers underflow to zero. But
> why did you not read the Example section of help(rgamma)? The effect is
> clearly indicated there.
>
>>
>>> x1 <- rgamma(10000, shape=0.001, scale=0.001)
>>> sd1 <- 1/sqrt(x1)
>>> truehist(sd1, xlim=c(0, 1.5))
>>>
>> Error in truehist(sd1, xlim = c(0, 1.5)) :
>> 'nbins' must result in a positive integer
>>
>>> summary(sd1)
>>>
>> Min. 1st Qu. Median Mean 3rd Qu. Max.
>> 2.266e+01 9.311e+66 3.250e+153 Inf Inf Inf
>>
>>
>>
>> ---------------------------------
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list