Package Exports
- compute-nanvariance
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compute-nanvariance) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
nanvariance
Computes the sample variance over an array of values ignoring any values which are not numeric.
Installation
$ npm install compute-nanvariance
For use in the browser, use browserify.
Usage
To use the module,
var nanvariance = require( 'compute-nanvariance' );
nanvariance( arr )
Computes the sample variance ignoring non-numeric values.
var data = [ 10, 2, 100, NaN, 34, NaN, 0 ];
var s2 = nanvariance( data );
Examples
var nanvariance = require( 'compute-nanvariance' );
var data = new Array( 1000 );
for ( var i = 0; i < data.length; i++ ) {
if ( i%5 === 0 ) {
data[ i ] = NaN;
} else {
data[ i ] = Math.random() * 100;
}
}
console.log( nanvariance( data ) );
To run the example code from the top-level application directory,
$ node ./examples/index.js
Notes
The sample variance of an array containing non-numeric values is equal to the sample variance of an equivalent array which contains only the numeric values. Hence,
var d1 = [ 1, NaN, 2, 3, NaN ],
d2 = [ 1, 2, 3 ];
console.log( nanvariance( d1 ) === nanvariance( d2 ) );
// returns true
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
Copyright
Copyright © 2014. Athan Reines.