Learn R Programming

distributions3 (version 0.3.0)

cdf.Empirical: Evaluate the cumulative distribution function of an Empirical distribution

Description

Please see the documentation of Empirical() for some properties of the Empirical distribution.

Usage

# S3 method for Empirical
cdf(d, x, drop = TRUE, elementwise = NULL, ...)

Value

In case of a single distribution object, either a numeric vector of length probs (if drop = TRUE, default) or a matrix with length(x) columns (if drop = FALSE). In case of a vectorized distribution object, a matrix with length(x) columns containing all possible combinations.

Arguments

d

An Empirical object created by a call to Empirical().

x

A vector of elements whose cumulative probabilities you would like to determine given the distribution d.

drop

logical. Should the result be simplified to a vector if possible?

elementwise

logical. Should each distribution in d be evaluated at all elements of x (elementwise = FALSE, yielding a matrix)? Or, if d and x have the same length, should the evaluation be done element by element (elementwise = TRUE, yielding a vector)? The default of NULL means that elementwise = TRUE is used if the lengths match and otherwise elementwise = FALSE is used.

...

arguments to be passed to pempirical().

See Also

Other Empirical distribution: Empirical(), dempirical(), pdf.Empirical(), quantile.Empirical(), random.Empirical(), support.Empirical()

Examples

Run this code

set.seed(28)

X <- Empirical(rnorm(50))
X

mean(X)
variance(X)
skewness(X)
kurtosis(X)

random(X, 10)

pdf(X, 2)
log_pdf(X, 2)

cdf(X, 4)
quantile(X, 0.7)

### example: allowed types/classes of input arguments

## Single vector (will be coerced to numeric)
Y1 <- rnorm(3, mean = -10)
d1 <- Empirical(Y1)
d1
mean(d1)

## Unnamed list of vectors
Y2 <- list(as.character(rnorm(3, mean = -10)),
           runif(6),
           rpois(4, lambda = 15))
d2 <- Empirical(Y2)
d2
mean(d2)

## Named list of vectors
Y3 <- list("Normal"  = as.character(rnorm(3, mean = -10)),
           "Uniform" = runif(6),
           "Poisson" = rpois(4, lambda = 15))
d3 <- Empirical(Y3)
d3
mean(d3)

## Matrix
Y4 <- matrix(rnorm(20), ncol = 5,
             dimnames = list(paste0("D_", 1:4), paste0("obs_", 1:5)))
d4 <- Empirical(Y4)
d4

## Data frame
d5 <- Empirical(as.data.frame(Y4))
d5

identical(d4, d5)

mean(d5)
variance(d5)
skewness(d5)
kurtosis(d5)

pdf(d5, c(-0.5, 0, 0.5, 1)) # Defaults to elementwise = TRUE
pdf(d5, c(-0.5, 0, 0.5, 1), elementwise = FALSE)

cdf(d5, c(-0.5, 0, 0.5, 1)) # Defaults to elementwise = TRUE
cdf(d5, c(-0.5, 0, 0.5, 1), elementwise = FALSE)

quantile(d5, c(0.2, 0.4, 0.6, 0.8)) # Defaults to elementwise = TRUE
quantile(d5, c(0.2, 0.4, 0.6, 0.8), elementwise = FALSE)

## The quantile function is the inverse of the distribution
## function (cdf) if x in Y
set.seed(6020)
Y <- round(rlnorm(20, log(3), log(2)), 1)
d <- Empirical(Y)

cdf(d, 4.0)
quantile(d, cdf(d, 4.0))

Run the code above in your browser using DataLab