# RejSampling: Rejection Sampling Algorithm In SimoneHermann/BaPreStoPro: Bayesian Prediction of Stochastic Processes

## Description

Algorithm to sample from an arbitrary density function.

## Usage

 ```1 2``` ```RejSampling(Fun, dens, len, cand, grid = 0.001, method = c("vector", "free")) ```

## Arguments

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

## References

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

## Examples

 ```1 2 3 4 5``` ```plot(density(RejSampling(dens = function(x) dnorm(x, 5, 1), len = 500, cand = seq(2, 9, by = 0.001), method = "free"))) lines(density(RejSampling(dens = function(x) dnorm(x, 5, 1), len = 500, cand = seq(2, 9, by = 0.001), method = "vector")), col=2) curve(dnorm(x, 5, 1), from = 2, to = 8, add = TRUE, col = 3) ```

SimoneHermann/BaPreStoPro documentation built on May 10, 2017, 1:42 p.m.