rejSamp: Generate random numbers by rejection sampling

Description Usage Arguments Details Value Examples

View source: R/rejSamp.R

Description

Generate random numbers by rejection sampling

Usage

1
2
rejSamp(f, n = 1, min = 0, max = 1, g = NULL, rg = NULL,
  g.factor = 1)

Arguments

f

[function]
Function to be interpreted as probability density function.

n

[integer(1)]
Amount of random numbers to be generated. Default is 1.

min

[numeric(1)]

max

[numeric(1)]
Interval the generated random numbers are from. Default is (0, 1).

g

[function]
Probability density function of the instrumental distribution.

rg

[function]
Function that generates random numbers from the instrumental distribution.

g.factor

[numeric(1)]
Factor for g. Default is 1.

Details

If no instrumental distribution is specified, the uniform distribution is used.

The call g(x) should return the probability of the realisation x for the instrumental distribution g.

The choice of g.factor should guarantee f(x) < g.factor * g(x).

Value

n Random numbers from the function f interpreted as probality density function on the interval (min, max).

Examples

1
2
test <- function(x) x^2
rejSamp(f = test, n = 10, min = -1, max = 1)

Dotterbart/rejSamp documentation built on May 6, 2019, 2:53 p.m.