compute-trimean

1.0.0 • Public • Published

Trimean

NPM version Build Status Coverage Status Dependencies

Computes the trimean of a numeric array.

The trimean (or Tukey's trimean) is defined as the weighted average of a distribution's median and its two quartiles. The statistic measures a probability distribution's location and is a statistically resistant L-estimator, having a breakdown point of 25%. The statistic combines the robustness of the median, while accounting for a distribution's shape.

Installation

$ npm install compute-trimean

For use in the browser, use browserify.

Usage

To use the module,

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

trimean( arr[, opts] )

Computes the trimean of a numeric array.

var unsorted = [ 5, 8, 9, 1, 7, 6, 2 ];

var tri = trimean( unsorted );
// returns 5.5

If the input array is already sorted in ascending order, set the sorted options flag to true.

var sorted = [ 1, 2, 5, 6, 7, 8, 9 ];

var tri = trimean( sorted, {'sorted': true} );
// returns 5.5

Additional options are the same as for the quantile module and only apply when computing the first and third quartiles.

Examples

var data = new Array( 100 );

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

console.log( trimean( data ) );

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

$ node ./examples/index.js

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

Copyright © 2014. Rebekah Smith.

Package Sidebar

Install

npm i compute-trimean

Weekly Downloads

72

Version

1.0.0

License

none

Last publish

Collaborators

  • kgryte