| empiricalD | R Documentation |
Density, distribution function, quantile function and random generation for a discrete empirical distribution. This function is vectorized to accept different sets of ‘values’ or ‘prob’.
dempiricalD(x, values, prob = NULL, log = FALSE)
pempiricalD(q, values, prob = NULL, lower.tail = TRUE, log.p = FALSE)
qempiricalD(p, values, prob = NULL, lower.tail = TRUE, log.p = FALSE)
rempiricalD(n, values, prob = NULL)
x, q |
vector of quantiles. |
values |
vector or matrix of numerical values. See details. |
prob |
optional vector or matrix of counts or probabilities. See details. |
log, log.p |
logical; if ‘TRUE’, probabilities ‘p’ are given as ‘log(p)’. |
lower.tail |
logical; if ‘TRUE’ (default), probabilities are ‘P[X <= x]’, otherwise, ‘P[X > x]’. |
p |
vector of probabilities. |
n |
number of random values. If ‘length(n) > 1’, the length is taken to be the number required. |
If ‘prob’ is missing, the discrete distribution is obtained directly from the vector of ‘values’, otherwise ‘prob’ is used to weight the values. ‘prob’ is normalized before use. Thus, ‘prob’ may be the count of each ‘values’. ‘prob’ values should be non negative and their sum should not be 0.
‘values’ and/or ‘prob’ may vary: in that case, ‘values’ and/or ‘prob’ should be sent as matrices, the first row being used for the first element of ‘x’, ‘q’, ‘p’ or the first random value, the second row for the second element, ... Recycling is permitted if the number of rows of ‘prob’ and ‘values’ are equal or if the number of rows of ‘prob’ and/or ‘values’ is one.
‘rempiricalD(n, values, prob)’ with ‘values’ and ‘prob’ as vectors is equivalent to ‘sample(x=values, size=n, replace=TRUE, prob=prob)’.
‘dempiricalD’ gives the density, ‘pempiricalD’ gives the distribution function, ‘qempiricalD’ gives the quantile function and ‘rempiricalD’ generates random deviates.
In the future, the functions should be written for non numerical values.
sample, empiricalC.
dempiricalD(1:6, 2:6, prob=c(10, 10, 70, 0, 10))
pempiricalD(1:6, 2:6, prob=c(10, 10, 70, 0, 10))
qempiricalD(seq(0, 1, 0.1), 2:6, prob=c(10, 10, 70, 0, 10))
table(rempiricalD(10000, 2:6, prob=c(10, 10, 70, 0, 10)))
## Varying values
(values <- matrix(1:10, ncol=5))
dempiricalD(c(1, 1), values)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.