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