Learn R Programming

BaPreStoPro (version 0.1)

InvMethod: Inversion Method

Description

Algorithm to sample from cumulative distribution function, if no inverse function is analytically available.

Usage

InvMethod(Fun, len, candArea, grid = 1e-05, method = c("vector", "free"))

Arguments

Fun
cumulative distribution function
len
number of samples
candArea
candidate area
grid
fineness degree
method
vectorial ("vector") or not ("free")

References

Devroye, L. (1986). Non-Uniform Random Variate Generation. New York: Springer.

Examples

Run this code
test <- InvMethod(function(x) pnorm(x, 5, 1), 1000, candArea = c(0, 10), method = "free")
plot(density(test))
curve(dnorm(x, 5, 1), col = 2, add = TRUE)

Run the code above in your browser using DataLab