empiricalD | R Documentation |
Density, distribution 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. |
p |
Vector of probabilities. |
n |
Number of random values. If length(n) |
values |
Vector or matrix of numerical values. See details. |
prob |
Optional vector or matrix of count 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]’. |
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 matrixes, 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 of ‘x’, ‘q’, ‘p’ or random value, ... 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’ are 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))
## the first x apply to the first row : p = 0.2
## the second x to the second one: p = 0
dempiricalD(c(1, 1), values)
##Use with mc2d
##Non Parameteric Bootstrap
val <- c(100, 150, 170, 200)
pr <- c(6, 12, 6, 6)
out <- c("min", "mean", "max")
##First Bootstrap in the uncertainty dimension
(x <- mcstoc(rempiricalD, type = "U", outm = out, nvariates = 30, values = val, prob = pr))
##Second one in the variability dimension
mcstoc(rempiricalD, type = "VU", values = x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.