p <- pi
x <- y <- seq(0, 10, by = 1/8)
dltg1 <- dltgammaInc(0, y, mu = 1, p = pi); r1 <- with(dltg1, rho * exp(sigma)) ##
dltg2 <- dltgammaInc(x, Inf, mu = 1, p = pi); r2 <- with(dltg2, rho * exp(sigma))
str(dltg1)
stopifnot(identical(c(rho = "double", sigma = "double", method = "integer"),
sapply(dltg1, typeof)))
summary(as.data.frame(dltg1))
pg1 <- pgamma(q = y, shape = pi, lower.tail=TRUE)
pg2 <- pgamma(q = x, shape = pi, lower.tail=FALSE)
stopifnot(all.equal(r1 / gamma(pi), pg1, tolerance = 1e-14)) # seen 5.26e-15
stopifnot(all.equal(r2 / gamma(pi), pg2, tolerance = 1e-14)) # " 5.48e-15
if(requireNamespace("Rmpfr")) withAutoprint({
asN <- Rmpfr::asNumeric
mpfr <- Rmpfr::mpfr
iGam <- Rmpfr::igamma(a= mpfr(pi, 128),
x= mpfr(y, 128))
relErrV <- sfsmisc::relErrV
relE <- asN(relErrV(target = iGam, current = r2))
summary(relE)
plot(x, relE, type = "b", col=2, # not very good: at x ~= 3, goes up to 1e-14 !
main = "rel.Error(incGamma(pi, x)) vs x")
abline(h = 0, col = adjustcolor("gray", 0.75), lty = 2)
lines(x, asN(relErrV(iGam, pg2 * gamma(pi))), col = adjustcolor(4, 1/2), lwd=2)
## ## ==> R's pgamma() is *much* more accurate !! ==> how embarrassing for TOMS 1006 !?!?
legend("topright", expression(dltgammaInc(x, Inf, mu == 1, p == pi),
pgamma(x, pi, lower.tail== F) %*% Gamma(pi)),
col = c(palette()[2], adjustcolor(4, 1/2)), lwd = c(1, 2), pch = c(1, NA), bty = "n")
})
Run the code above in your browser using DataLab