Learn R Programming

mltools (version 0.2.0)

empirical_cdf: Empirical Cumulative Distribution Function

Description

Given a vector x, calculate P(x <= X) for a set of upper bounds X. Can be applied to a data.table object for multivariate use. That is, calculate P(x <= X, y <= Y, z <= Z, ...)

Usage

empirical_cdf(x = NULL, ubounds)

Arguments

x

Numeric vector or a data.table object

ubounds

A vector of upper bounds on which to evaluate the CDF. For multivariate version, a list whose names correspond to columns of x

Details

Calculate the empirical CDF of a vector. Alternatively, leave x blank and pass a named list of vectors for ubounds to return a grid of upper bounds that is the cartesian product of the vectors in ubounds

Examples

Run this code
library(data.table)
dt <- data.table(x=c(0.3, 1.3, 1.4, 3.6), y=c(1.2, 1.2, 3.8, 3.9))
empirical_cdf(dt$x, ubounds=as.numeric(1:4))
empirical_cdf(dt, ubounds=list(x=as.numeric(1:4)))
empirical_cdf(dt, ubounds=list(x=as.numeric(1:4), y=as.numeric(1:4)))
empirical_cdf(ubounds=list(x=as.numeric(1:4), y=as.numeric(1:4), z=as.numeric(1:2)))

Run the code above in your browser using DataLab