From p.dalgaard at biostat.ku.dk  Fri Sep 25 20:21:12 2009
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Fri, 25 Sep 2009 20:21:12 +0200
Subject: [Rd] Problem with dgamma function.
In-Reply-To: <8adccabf0909251101h4e181baey87afaa7ecc30a0e4@mail.gmail.com>
References: <8adccabf0909251101h4e181baey87afaa7ecc30a0e4@mail.gmail.com>
Message-ID: <4ABD0A18.3040804@biostat.ku.dk>

Charles Danko wrote:
> Hi, All,
> 
> I am getting some funny results trying to use R's built in
> distribution functions.
> 
> In R:
>> dgamma(4.775972,1.37697964405418, 0.106516604930466)
> [1] 0.05585295
>> dgamma(4.775972,1.37697964405418, 0.106516604930466,TRUE)  ### THIS IS JUST WRONG!
> [1] 0.01710129
>> log(dgamma(4.775972,1.37697964405418, 0.106516604930466))
> [1] -2.885033
> 
> In C:
> dgamma(4.775972,1.37697964405418, 0.106516604930466,TRUE)
> Returns: -41.046764
> 
> dgamma(4.775972,1.37697964405418, 0.106516604930466,FALSE)
> Returns: 0.000000
> 
> SESSION INFO:
> R version 2.9.0 (2009-04-17)
> x86_64-unknown-linux-gnu
> 
> Any indication of what I may be doing wrong is very much appreciated.

Not reading the documentation?

 > args(dgamma)
function (x, shape, rate = 1, scale = 1/rate, log = FALSE)
NULL
 > dgamma(4.775972,1.37697964405418,, 0.106516604930466,TRUE)
[1] -41.04676
 > dgamma(4.775972,1.37697964405418,, 0.106516604930466,FALSE)
[1] 1.491480e-18
 > log(dgamma(4.775972,1.37697964405418,, 0.106516604930466,FALSE))
[1] -41.04676
 > dgamma(4.775972,1.37697964405418,0.106516604930466,log=TRUE)
[1] -2.885033
 >

> Thanks,
> Charles
> 
> 


-- 
    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] Problem with dgamma function.
Peter Dalgaard