Learn R Programming

Runuran (version 0.40)

ud: Density function for "unuran" object

Description

Evaluates the probability density function (PDF) or probability mass function (PMF) for a "unuran" object for a continuous and discrete distribution, respectively.

Usage

ud(obj, x, islog = FALSE)

Arguments

obj

one of

  • a distribution object of class "unuran.cont" that contains the PDF, or

  • a distribution object of class "unuran.discr" that contains the PMF, or

  • a generator object (class "unuran") that contains the PDF and PMF, resp.

x

vector of x values. (numeric)

islog

if TRUE, the log-density is returnd. (boolean)

Author

Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.

Details

The routine evaluates the probability density function of a distribution stored in a UNU.RAN distribution object or UNU.RAN generator object. If islog is TRUE, then the logarithm of the density is returned.

If the PDF (or its respective logarithm) is not available in the object, then NA is returned and a warning is thrown.

Note: when the log-density is not given explicitly (by setting islog=TRUE in the corresponding routing like unuran.cont.new or in an Runuran built-in distribution), then NA is returned even if the density is given.

Important: Routine ud just evaluates the density function that is stored in obj. It ignores the boundaries of the domain of the distribution, i.e., it does not return 0 outside the domain unless the implementation of the PDF handles this case correctly. This behavior is in particular important when Runuran built-in distributions are truncated by explicitly setting the domain boundaries.

References

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

See Also

unuran.cont, unuran.discr, unuran.

Examples

Run this code
## Create an UNU.RAN distribution object (for standard Gaussian)
## and evaluate density for some points
distr <- udnorm()
ud(distr, 1.5)
ud(distr, -3:3)

## Create an UNU.RAN generator object (for standard Gaussian)
## and evaluate density of underyling distribution
gen <- tdrd.new(udnorm())
ud(gen, 1.5)
ud(gen, -3:3)

Run the code above in your browser using DataLab