Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compute-quantile

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compute-quantile

Computes a quantile for a numeric array.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-32.01%
Maintainers
1
Weekly downloads
 
Created
Source

Quantile

NPM version Build Status Coverage Status Dependencies

Computes a quantile for a numeric array.

This module determines the nearest rank and returns the array value corresponding to that rank.

This module does not currently support multiple interpolation methods, and instead uses a standard elementary method for estimating the quantile.

Installation

$ npm install compute-quantile

For use in the browser, use browserify.

Usage

To use the module,

var quantile = require( 'compute-quantile' );
quantile( arr, p[, opts] )

Given a probability 0 <= p <= 1, computes the quantile for an input array.

var unsorted = [ 4, 3, 5, 1, 2 ];

var q = quantile( unsorted, 0.25 );
// returns 2

If the input array is already sorted in ascending order, you can set the sorted option to true.

var sorted = [ 1, 2, 3, 4, 5 ];

var q = quantile( sorted, 0.25, { 'sorted': true } );
// returns 2

Examples

var quantile = require( 'compute-quantile' );

// Simulate some data...
var data = new Array( 1000 );

for ( var i = 0, len = data.length; i < len; i++ ) {
	data[ i ] = Math.round( Math.random()*1000 );
}

// Compute the p-quantile for p = 0.5 (median):
console.log( quantile( data, 0.5 ) );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Notes

The probability p is equal to k / q, where q is the total number of quantiles and k is the k th quantile.

If the input array is not sorted in ascending order, the function is O( N log(N) ), where N is the input array length. If the array is sorted, the function is O(1).

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.


Copyright © 2014. Athan Reines.

Keywords

FAQs

Package last updated on 05 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc