log, log.p: logical; if TRUE, probabilities p are given as log(p).
lower.tail: logical; if TRUE (default), moments are E[xr∣X≤y], otherwise, E[xr∣X>y]
p: vector of probabilities
r: rth raw moment of the Pareto distribution
truncation: lower truncation parameter, defaults to NULL.
Returns
dempirical returns the density, pempirical the distribution function, qempirical the quantile function, mempirical gives the rth moment of the distribution or a function that allows to evaluate the rth moment of the distribution if truncation is NULL..
Details
The density function is a standard Kernel density estimation for 1e6 equally spaced points. The cumulative Distribution Function:
Fn(x)=n1i=1∑nIxi≤x
The y-bounded r-th raw moment of the empirical distribution equals:
μyr=n1i=1∑nIxi≤xxr
Examples
#'## Generate random sample to work withx <- rlnorm(1e5, meanlog =-0.5, sdlog =0.5)## Empirical densityplot(x = seq(0,5, length.out =100), y = dempirical(x = seq(0,5, length.out =100), data = x))# Compare empirical and parametric quantitiesdlnorm(0.5, meanlog =-0.5, sdlog =0.5)dempirical(0.5, data = x)plnorm(0.5, meanlog =-0.5, sdlog =0.5)pempirical(0.5, data = x)qlnorm(0.5, meanlog =-0.5, sdlog =0.5)qempirical(0.5, data = x)mlnorm(r =0, truncation =0.5, meanlog =-0.5, sdlog =0.5)mempirical(r =0, truncation =0.5, data = x)mlnorm(r =1, truncation =0.5, meanlog =-0.5, sdlog =0.5)mempirical(r =1, truncation =0.5, data = x)## Demonstration of log functionailty for probability and quantile functionquantile(x,0.5, type =1)qempirical(p = pempirical(q = quantile(x,0.5, type =1), data = x, log.p =TRUE),data = x, log.p =TRUE)## The zeroth truncated moment is equivalent to the probability functionpempirical(q = quantile(x,0.5, type =1), data = x)mempirical(truncation = quantile(x,0.5, type =1), data = x)## The (truncated) first moment is equivalent to the mean of a (truncated) random sample,#for large enough samples.mean(x)mempirical(r =1, data = x, truncation =0, lower.tail =FALSE)sum(x[x > quantile(x,0.1)])/ length(x)mempirical(r =1, data = x, truncation = quantile(x,0.1), lower.tail =FALSE)#'