rvdens: Sample from an arbitrary density function using grid...

Description Usage Arguments Value Note Author(s) References Examples

View source: R/rvdens.R

Description

rvdens generates a random vector where each simulation comes from a Bernoulli sampling distribution.

Usage

1
rvdens(n = 1, FUN, range, unitprecision = 10, ...)

Arguments

n

number of random scalars to draw

FUN

density function

range

range to discretize over

unitprecision

how many points per unit length

...

other arguments passed on to FUN

Value

A random vector (an rv object) of length n.

Note

The resulting vector will not be independent and identically distributed Bernoulli unless prob is a fixed number.

Author(s)

Jouni Kerman jouni@kerman.com

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

Examples

1
2
  x <- rvdens(FUN=stats:::dnorm, range=c(-5, 5), unitprecision=10)
  y <- rvnorm(1) ## Should be close to x

jsta/rv documentation built on Feb. 12, 2022, 5:13 p.m.