Learn R Programming

GoFKernel (version 2.1-1)

random.function: Random Draw Generator

Description

This function generates random draws of a continuous random variable given either its density or its cumulative distribution function.

Usage

random.function(n = 1, f, lower = -Inf, upper = Inf, kind = "density")

Arguments

n

number of draws, default 1.

f

either a density (default) or cumulative distribution function of the random variable.

lower

lower limit of the support of the random variable, default -Inf.

upper

upper limit of the support of the random variable, default Inf.

kind

character string with the function used to identify the distribution, either "density" (default) or "cumulative", as alternative.

Value

A vector of length n with n draws from a random variable with density (or cumulative distribution) function given by f.

Details

random.function uses the method of the inverse of the cdf to generate random draws from f.

See Also

dgeometric.test, integrate, inverse and support.facto.

Examples

Run this code
# NOT RUN {
f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
random.function(10, f0, lower=0, upper=1, kind="density")
# }

Run the code above in your browser using DataLab