The “rgamma” Function in R
Package: Base R (no specific package required)
Purpose: Generates random numbers from a gamma distribution.
General Class: Random Number Generation
Required Argument(s):
n: The number of random values to generate.
shape: The shape parameter of the gamma distribution.
Notable Optional Arguments:
rate: The rate parameter of the gamma distribution.
scale: An alternative to the rate parameter, specifying the scale of the gamma distribution (scale = 1/rate).
Example:
# Generate 100 random values from a gamma distribution with shape 2 and rate 0.5
random_values <- rgamma(n = 100, shape = 2, rate = 0.5)
print(random_values)In this example, the rgamma function is used to generate 100 random values from a gamma distribution with a shape parameter of 2 and a rate parameter of 0.5. The generated values are then printed to the console.