[R] Incomplete Gamma function
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Aug 31 15:06:42 CEST 2007
On Fri, 31 Aug 2007, Robin Hankin wrote:
> Hi Kris
>
>
> lgamma() gives the log of the gamma function.
Yes, but he used Igamma. According to ?pgamma,
'pgamma' is closely related to the incomplete gamma function. As
defined by Abramowitz and Stegun 6.5.1
P(a,x) = 1/Gamma(a) integral_0^x t^(a-1) exp(-t) dt
P(a, x) is 'pgamma(x, a)'. Other authors (for example Karl
Pearson in his 1922 tables) omit the normalizing factor, defining
the incomplete gamma function as 'pgamma(x, a) * gamma(a)'.
and that seems to be what Igamma is following. GSL on the other hand has
the other tail, so
> a <- 9
> x <- 11.1
> pgamma(x, a, lower=FALSE)*gamma(a)
[1] 9000.501
>
> You need gamma_inc() of the gsl package, a wrapper for the
> GSL library:
>
> > gamma_inc(9,11.1)
> [1] 9000.501
> >
As the above shows, you don't *need* this, but you do need the GSL
documentation to find out what R package gsl does. Why it differs from
the usual references is something for you to explain. Wikipedia
http://en.wikipedia.org/wiki/Incomplete_gamma_function
distinguishes them, as does MathWorld.
I suggest you add a clarification to the gsl package as to what the
'incomplete gamma function' means there.
> On 31 Aug 2007, at 00:29, poolloopus at yahoo.com wrote:
>
>> Hello
>>
>> I am trying to evaluate an Incomplete gamma function
>> in R. Library Zipfr gives the Igamma function. From
>> Mathematica, I have:
>>
>> "Gamma[a, z] is the incomplete gamma function."
>>
>> In[16]: Gamma[9,11.1]
>> Out[16]: 9000.5
>>
>> Trying the same in R, I get
>>
>>> Igamma(9,11.1)
>> [1] 31319.5
>> OR
>>> Igamma(11.1,9)
>> [1] 1300998
>>
>> I know I have to understand the theory and the math
>> behind it rather than just ask for help, but while I
>> am trying to do that (and only taking baby steps, I
>> must admit), I was hoping someone could help me out.
>>
>> Regard
>>
>> Kris.
>>
>>
>>
>> ______________________________________________________________________
>> ______________
>> Got a little couch potato?
>> Check out fun summer activities for kids.
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
> tel 023-8059-7743
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list