Skip to contents

Generates random observations from a gamma distribution truncated to the interval \((lower, upper)\) using inverse transform sampling.

Usage

rgammat(n, shape, scale, lower, upper)

Arguments

n

Integer. Number of observations to generate.

shape

Numeric. Shape parameter of the gamma distribution.

scale

Numeric. Scale parameter of the gamma distribution.

lower

Numeric. Lower truncation bound.

upper

Numeric. Upper truncation bound.

Value

A numeric vector of length n containing random draws from the truncated gamma distribution.

Details

Random values are generated by sampling from a uniform distribution on the interval \([F(lower), F(upper)]\), where \(F\) is the CDF of the gamma distribution, and then applying the inverse CDF.

This approach ensures that the generated values follow the truncated distribution exactly.

The implementation is based on the inverse transform method as described in: https://www.r-bloggers.com/2020/08/generating-data-from-a-truncated-distribution/

Author

Martin Haringa