Description Usage Arguments Details Value Author(s) References See Also Examples

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on Adaptive Rejection Sampling (‘ARS’).

[Universal] – Rejection Method.

1 2 |

`logpdf` |
log-density function. ( |

`dlogpdf` |
derivative of |

`lb` |
lower bound of domain;
use |

`ub` |
upper bound of domain;
use |

`...` |
(optional) arguments for |

`distr` |
distribution object. (S4 object of class |

This function creates a `unuran`

object based on ‘ARS’
(Adaptive Rejection Sampling). It can be used to draw samples from
continuous distributions with given probability density function
using `ur`

.

Function `logpdf`

is the logarithm the density function of the
target distribution. It must be a concave function (i.e., the
distribution must be log-concave).
However, it need not be normalized (i.e., it can be a log-density plus
some arbitrary constant).

The derivative `dlogpdf`

of the log-density is optional. If
omitted, numerical differentiation is used. Notice, however, that this
might cause some round-off errors such that the algorithm fails.

Alternatively, one can use function `arsd.new`

where the object
`distr`

of class `"unuran.cont"`

must contain all required
information about the distribution.

The setup time of this method depends on the given PDF, whereas its marginal generation times are almost independent of the target distribution.

‘ARS’ is a special case of method ‘TDR’
(see `tdr.new`

). It is a bit slower and less
flexible but numerically more stable. In particular, it is useful if
one wants to sample from truncated distributions with extreme
truncation points; or when the integral of the given “density”
function is only known to be extremely large or small.
However, this assumes that the log-density is computed
analytically and not by just using `log(pdf(x))`

.

An object of class `"unuran"`

.

Josef Leydold and Wolfgang H\"ormann [email protected].

W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Chapter 4 (Tranformed Density Rejection).

W. R. Gilks and P. Wild (1992): Adaptive rejection sampling for Gibbs sampling. Applied Statistics 41(2), pp. 337–348.

`ur`

,
`tdr.new`

,
`unuran.cont`

,
`unuran.new`

,
`unuran`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ```
## Create a sample of size 100 for a
## Gaussian distribution (use logPDF)
lpdf <- function (x) { -0.5*x^2 }
gen <- ars.new(logpdf=lpdf, lb=-Inf, ub=Inf)
x <- ur(gen,100)
## Same example but additionally provide derivative of log-density
## to prevent possible round-off errors
lpdf <- function (x) { -0.5*x^2 }
dlpdf <- function (x) { -x }
gen <- ars.new(logpdf=lpdf, dlogpdf=dlpdf, lb=-Inf, ub=Inf)
x <- ur(gen,100)
## Draw a sample from a truncated Gaussian distribution
## on domain [100,Inf)
lpdf <- function (x) { -0.5*x^2 }
gen <- ars.new(logpdf=lpdf, lb=50, ub=Inf)
x <- ur(gen,100)
## Alternative approach
distr <- udnorm()
gen <- arsd.new(distr)
x <- ur(gen,100)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.