A.Noufaily
2009-Dec-11 16:13 UTC
[R] Regularized gamma function/ incomplete gamma function
Dear all, I would be very grateful if you could help me with: Given the regularized gamma function Reg=int_0^r (x^(k-1)e^(-x))dx/int_0^Inf (x^(k-1)e^(-x))dx ; 0<r<Inf (which is eventually the ratio of the Incomplete gamma function by the gamma function), does anyone know of a package in R that would evaluate the derivative of the inverse of Reg with respect to k? I am aware that the function "Rgamma.inv" of the package "Zipfr" evaluates the inverse of Reg and I'm wondering wether there is a function that would evaluate the derivative of the inverse.. Alternatively, a good numerical integration package/ or simply a function that could evaluate the integral int_0^r (log(x) x^(k-1) e^(-x))dx; 0<r<Inf would be useful. I tried the function "int" of the package "rmutil" but I'm not sure wether it is accurate especially for small values of k. Does R have a powerful numerical integration package that can deal with such functions especially when the limit close to zero in + or - Inf? Many thanks for this opportunity to post our queries, Amy ________________________________ The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). [[alternative HTML version deleted]]
Stefan Evert
2009-Dec-11 23:05 UTC
[R] Regularized gamma function/ incomplete gamma function
> I would be very grateful if you could help me with: > > Given the regularized gamma function Reg=int_0^r (x^(k-1)e^(-x))dx/ > int_0^Inf (x^(k-1)e^(-x))dx ; 0<r<Inf (which is eventually the ratio > of the > Incomplete gamma function by the gamma function), does anyone know > of a package in R that would evaluate the derivative of the inverse > of Reg with respect to k?This doesn't look pleasant at all: http://en.wikipedia.org/wiki/Incomplete_gamma_function#Derivatives It appears to be quite difficult to compute the derivative of the incomplete gamma function itself -- I'm not aware of any R implementation -- and the derivative of the inverse may be even harder.> I am aware that the function "Rgamma.inv" of the package "Zipfr" > evaluates the inverse > of Reg and I'm wondering wether there is a function that would > evaluate the derivative of the inverse..For all I know, the inverse is calculated by an (optimized) Newton- type search algorithm, so it's not very likely that its derivative can easily be worked out (based on the current implementation). Best, Stefan
Ravi Varadhan
2009-Dec-11 23:49 UTC
[R] Regularized gamma function/ incomplete gamma function
You can do this using the package "numDeriv". require(zipfR) require(numDeriv) fn <- function(x, y) Rgamma.inv(x, y) gRgamma.inv <- function(y, k) sapply(y, function(y) grad(x=k, func=fn, y=y)) plot(gRgamma.inv(y=seq(0,1, length=200), k=1), type="l", xlab="x", ylab="Derivative of Rgamma.inv w.r.t. `k' ") lines(gRgamma.inv(seq(0,1, length=200), k=2), col=2) lines(gRgamma.inv(seq(0,1, length=200), k=5), col=3) lines(gRgamma.inv(seq(0,1, length=200), k=10), col=4) I hope this helps, Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvaradhan at jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of A.Noufaily Sent: Friday, December 11, 2009 11:13 AM To: r-help at R-project.org Subject: [R] Regularized gamma function/ incomplete gamma function Dear all, I would be very grateful if you could help me with: Given the regularized gamma function Reg=int_0^r (x^(k-1)e^(-x))dx/int_0^Inf (x^(k-1)e^(-x))dx ; 0<r<Inf (which is eventually the ratio of the Incomplete gamma function by the gamma function), does anyone know of a package in R that would evaluate the derivative of the inverse of Reg with respect to k? I am aware that the function "Rgamma.inv" of the package "Zipfr" evaluates the inverse of Reg and I'm wondering wether there is a function that would evaluate the derivative of the inverse.. Alternatively, a good numerical integration package/ or simply a function that could evaluate the integral int_0^r (log(x) x^(k-1) e^(-x))dx; 0<r<Inf would be useful. I tried the function "int" of the package "rmutil" but I'm not sure wether it is accurate especially for small values of k. Does R have a powerful numerical integration package that can deal with such functions especially when the limit close to zero in + or - Inf? Many thanks for this opportunity to post our queries, Amy ________________________________ The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). [[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.