Description Usage Arguments Details Value See Also Examples
Implementation of d/p/q/r functions for xDensity distributions.
1 2 3 4 5 6 7 |
x, q |
Vector of quantiles. |
xDens |
Object of class |
log, log.p |
Logical; if |
lower.tail |
Logical; if |
p |
Vector of probabilities. |
n |
Number of observations. |
Extended density (or xDensity) objects provide a compact representation of arbitrary one-dimensional distributions defined on the real line. That is, an xDensity object is a list with the following elements:
xrng, ndens: range and number of gridpoints defining the main density region, i.e. xseq = seq(xrng[1], xrng[2], len = xn).
ypdf, ylpdf, ycdf: density, log-density, and cdf on the grid.
mean, sd: mean and standard deviation of a Normal distribution to use outside the specified density range.
For the underlying xDensity object, dXD gives the density, pXD gives the distribution function, qXD gives the quantile function and rXD generates n random values.
matrixXD, kernelXD, gc4XD for various xDensity object constructors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # xDensity representation of a N(0,1) distribution
# construct the xDensity object using the known PDF dnorm
xseq <- seq(-4, 4, len = 500) # where to evaluate density
xDens <- matrixXD(cbind(xseq, dnorm(xseq)))
# check random sampling
x <- rXD(1e5, xDens = xDens)
hist(x, breaks = 100, freq = FALSE)
curve(dnorm, add = TRUE, col = "red")
# check PDF
x <- rnorm(5)
rbind(true = dnorm(x, log = TRUE), xDens = dXD(x, xDens, log = TRUE))
# check CDF
rbind(true = pnorm(x, log = TRUE), xDens = pXD(x, xDens, log = TRUE))
# check inverse-CDF
probs <- runif(5)
rbind(true = qnorm(probs), xDens = qXD(probs, xDens))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.