heavy (version 0.38.196)

tgamma: The right truncated gamma distribution

Description

Density, distribution function, quantile function and random generation for the right truncated gamma distribution with shape (shape), scale (scale) parameters and right truncation point (truncation).

Usage

dtgamma(x, shape, scale = 1, truncation = 1, log = FALSE)
  ptgamma(q, shape, scale = 1, truncation = 1, lower.tail = TRUE)
  qtgamma(p, shape, scale = 1, truncation = 1, lower.tail = TRUE)
  rtgamma(n, shape, scale = 1, truncation = 1)

Arguments

x, q

vector of quantiles.

shape, scale

shape and scale parameters, must be positive.

truncation

right truncation point, must be positive.

log

logical; if TRUE, the log-density is returned.

lower.tail

logical; if TRUE (default), probabilities are \(P[X \le x]\), otherwise, \(P[X > x]\).

p

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number of required deviates.

Value

dtgamma, ptgamma, and qtgamma are respectively the density, distribution function and quantile function of the right truncated gamma distribution. rtgamma generates random deviates from the right truncated gamma distribution.

The length of the result is determined by n for rtgamma, and is the maximum of the lengths of the numerical parameters for the other functions.

Details

If scale or truncation are not specified, they assume the default values.

The right truncated gamma distribution with shape \(a\), scale \(b\) and right truncation point \(t > 0\) has density $$ f(x) = \frac{b^a}{\gamma(a,bt)} \exp(-bx)x^{a-1}$$ con \(x < t\) and \(\gamma(a,b)\) denotes the incomplete gamma function (see Abramowitz and Stegun, 1970, pp. 260).

References

Abramowitz, M., and Stegun, I.A. (1970). Handbook of Mathematical Functions. Dover, New York.

Phillippe, A. (1997). Simulation of right and left truncated gamma distribution by mixtures. Statistics and Computing 7, 173-181.

See Also

Distributions for other standard distributions.

Examples

Run this code
# NOT RUN {
x <- seq(0, 2, by = 0.1)
y <- dtgamma(x, shape = 1, truncation = 1)
z <- dgamma(x, shape = 1) # standard gamma pdf
plot(x, z, type = "l", xlab = "x", ylab = "density", ylim = range(y, z), lty = 2)
lines(x, y)

x <- rtgamma(1000, shape = 1)
## Q-Q plot for the right truncated gamma data against true theoretical distribution:
qqplot(qtgamma(ppoints(1000), shape = 1), x, main = "Truncated Gamma Q-Q plot",
  xlab = "Theoretical quantiles", ylab = "Sample quantiles", font.main = 1)
abline(c(0,1), col = "red", lwd = 2)
# }

Run the code above in your browser using DataLab