# empiricalD: The Discrete Empirical Distribution In mc2d: Tools for Two-Dimensional Monte-Carlo Simulations

## Description

Density, distribution function and random generation for a discrete empirical distribution. This function is vectorized to accept different sets of values or prob.

## Usage

 ```1 2 3 4``` ```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) ```

## Arguments

 `x, q` Vector of quantiles. `p` Vector of probabilities. `n` Number of random values. If length(n) > 1, the length is taken to be the number required. `values` Vector or matrix of numerical values. See details. `prob` Optionnal 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].

## Details

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).

## Value

dempiricalD gives the density, pempiricalD gives the distribution function, qempiricalD gives the quantile function and rempiricalD generates random deviates.

## Note

In the future, the fonctions should be written for non numerical values.

`sample`. `empiricalC`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21``` ```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) ```