Learn R Programming

distributions3 (version 0.3.0)

random.distribution: Inverse transform sampling for random number generation

Description

Generates random numbers from a distribution object by mapping uniform random variates through the target quantile function.

Usage

# S3 method for distribution
random(x, n = 1L, drop = TRUE, ...)

Value

A numeric vector of random values if length(d) equals one or n = 1L and drop = TRUE (default), or a matrix where rows correspond to the distribution(s) d whilst the columns contain the random values.

Arguments

x

An object of class distribution.

n

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

drop

logical. Should the result be simplified to a vector if possible?

...

currently unused.

Examples

Run this code
## Drawing random numbers from a Poisson distribution
## using the inverse transform sampling method
random.distribution(Poisson(3), n = 6)

## Drawing random numbers from a series of Normal distributions
## using the inverse transform sampling method
random.distribution(Normal(1:3, 1:3 / 2), n = 6)

Run the code above in your browser using DataLab