Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environmentand already has all of npm's 300,000 packages pre-installed, including cumulative-distribution-function with all npm packages installed. Try it out:

var cumulativeDistributionFunction = require("cumulative-distribution-function")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

cumulative-distribution-function v1.0.2

create empirical cumulative distribution function from array of values


Build Status Coverage Status

Calculates statistical cumulative distribution function from data array of x values.


npm i cumulative-distribution-function -S


None. Suitable for usage on nodejs or on the browser, via browserify.


const cdf = require('cumulative-distribution-function');


Pass a numeric data array as input, cdf(data) returns a function, the empirical cumulative distribution function, a step function that counts the proportion of data less than or equal to the input x.

The function returned by cdf(data) takes a number x and returns the proportion of values less than or equal to x.


var mydata = [13,2,5,3,23,7,11,13,19,23];
var mycdf  = cdf(mydata); // cdf(mydata) returns a **function**, so mycdf is a **function**
mycdf(-5)  // 0.0 because all mydata are greater than -5
mycdf(2)  // 0.1 because 1 of 10 mydata are less than or equal to 2
mycdf(3)  // 0.2 because 2 of 10 mydata are less than or equal to 3
mycdf(13) // 0.7 because 7 of 10 mydata are less than or equal to 13
mycdf(19) // 0.8 because 8 of 10 mydata are less than or equal to 19
mycdf(20) // 0.8 because 8 of 10 mydata are less than or equal to 20
mycdf(25) // 1.0 because all mydata are less than or equal to 25
mycdf.xs() // returns [2,    3,  5,  7, 11, 13, 19, 23] from sorted, unique mydata // returns [0.1,0.2,0.3,0.4,0.5,0.7,0.8,1.0] from corresponding cumulative proportions

##Missing or Empty Data

Calling cdf with a missing or empty data array returns a function that returns undefined.

The .xs() and .ps() auxiliary functions will return empty arrays.

var mycdf = cdf([]); // empty or missing data
mycdf(5) // returns undefined 
mycdf.xs() // returns empty array [] // returns empty array []


Use mocha framework.


Copyright 2016 Paul Brewer, Economic and Financial Technology Consulting LLC



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free