Learn R Programming

Rsubbotools (version 0.0.1)

rgamma_c: Generates a Gamma-distributed sample

Description

Returns a sample from a gamma-distributed random variable. The function uses the Marsaglia-Tsang fast gamma method used to generate the random samples. See more details below. The name was chosen so it doesn't clash with R's native method.

Usage

rgamma_c(n, b = 2, a = 1/2)

Value

a numeric vector containing a random sample with above parameters.

Arguments

n

(int)

b

(numeric) - shape parameter. Must be in the range \((0, \infty)\).

a

(numeric) - scale parameter. Must be in the range \((0, \infty)\).

Details

The gamma distribution is given by the function: $$f(x) = \frac{1}{\Gamma(b)a^b}x^{b-1}e^{-x/a}, x > 0$$ where \(b\) is a shape parameter and \(a\) is a scale parameter. The RNG is given by Marsaglia and Tsang, "A Simple Method for generating gamma variables", ACM Transactions on Mathematical Software, Vol 26, No 3 (2000), p363-372. Available at tools:::Rd_expr_doi("10.1145/358407.358414"). The code is based on the original 'GSL' version, adapted to use 'R' version of RNGs. All credits to the original authors. Implemented by J.D.Lamb@btinternet.com, minor modifications for 'GSL' by Brian Gough. Adapted to 'R' by Elias Haddad.

Examples

Run this code
sample_gamma <- rgamma_c(1000, 1, 1)

Run the code above in your browser using DataLab