diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md new file mode 100644 index 000000000000..8274143bed05 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -0,0 +1,207 @@ + + +# incrnancv + +> Compute the [coefficient of variation][coefficient-of-variation] (CV) incrementally, while ignoring 'NaN' values. + +
+ +The [corrected sample standard deviation][sample-stdev] is defined as + + + +```math +s = \sqrt{\frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2} +``` + + + + + +and the [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The [coefficient of variation][coefficient-of-variation] (also known as **relative standard deviation**, RSD) is defined as + + + +```math +c_v = \frac{s}{\bar{x}} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnancv = require( '@stdlib/stats/incr/nancv' ); +``` + +#### incrnancv( \[mean] ) + +Returns an accumulator `function` which incrementally computes the [coefficient of variation][coefficient-of-variation], while ignoring 'NaN' value. + +```javascript +var accumulator = incrnancv(); +``` + +If the mean is already known, provide a `mean` argument. + +```javascript +var accumulator = incrnancv( 3.0 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated accumulated value. If not provided an input value `x`, the accumulator function returns the current accumulated value. + +```javascript +var accumulator = incrnancv(); + +var cv = accumulator( 2.0 ); +// returns 0.0 + +cv = accumulator( 1.0 ); +// returns 0.47140452079103173 + +cv = accumulator( NaN ); +// returns 0.4714045207910317 + +cv = accumulator( 3.0 ); +// returns 0.5 + +cv = accumulator(); +// returns 0.5 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **all** future invocations. +- The [coefficient of variation][coefficient-of-variation] is typically computed on nonnegative values. The measure may lack meaning for data which can assume both positive and negative values. +- For small and moderately sized samples, the accumulated value tends to be too low and is thus a **biased** estimator. Provided the generating distribution is known (e.g., a normal distribution), you may want to adjust the accumulated value or use an alternative implementation providing an unbiased estimator. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnancv = require( '@stdlib/stats/incr/nancv' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnancv(); + +// For each simulated datum, update the coefficient of variation... +for ( i = 0; i < 100; i++ ) { + v = ( (randu() < 0.1) ? NaN : (randu() * 100.0) ); + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js new file mode 100644 index 000000000000..a5509bf17cf5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnancv = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnancv(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnancv(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator,known_mean', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnancv( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt new file mode 100644 index 000000000000..0ebe3261bc0b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt @@ -0,0 +1,38 @@ +{{alias}}( [mean] ) + Returns an accumulator function which incrementally computes the + coefficient of variation (CV), ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated + accumulated value. If not provided a value, the accumulator function + returns the current accumulated value. + + If all received values are `NaN`, the accumulated value remains `null`. + + Parameters + ---------- + mean: number (optional) + Known mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var cv = accumulator() + null + > cv = accumulator( NaN ) + null + > cv = accumulator( 2.0 ) + 0.0 + > cv = accumulator( 1.0 ) + ~0.47 + > cv = accumulator( NaN ) + ~0.47 + > cv = accumulator() + ~0.47 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts new file mode 100644 index 000000000000..8f2ef43c8eed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts @@ -0,0 +1,67 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* +* @param x - value +* @returns accumulated value or null +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring `NaN` values. +* +* @param mean - mean value +* @returns accumulator function +* +* @example +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* cv = accumulator( NaN ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +* +* @example +* var accumulator = incrnancv( 3.14 ); +*/ +declare function incrnancv( mean?: number ): accumulator; + + +// EXPORTS // + +export = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts new file mode 100644 index 000000000000..44fe3a4d50f3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnancv = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnancv(); // $ExpectType accumulator + incrnancv( 0.0 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + incrnancv( '5' ); // $ExpectError + incrnancv( true ); // $ExpectError + incrnancv( false ); // $ExpectError + incrnancv( null ); // $ExpectError + incrnancv( [] ); // $ExpectError + incrnancv( {} ); // $ExpectError + incrnancv( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnancv(); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnancv(); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js new file mode 100644 index 000000000000..e15dd209e030 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnancv = require( './../lib' ); + +var accumulator; +var cv; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnancv(); + +// For each simulated datum, update the coefficient of variation, ignoring NaN values... +console.log( '\nValue\tCV\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( (randu() < 0.1) ? NaN : (randu() * 100.0) ); + cv = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), cv.toFixed( 4 ) ); +} +console.log( '\nFinal CV: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js new file mode 100644 index 000000000000..b7078cfde7fe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the coefficient of variation (CV) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nancv +* +* @example +* var incrnancv = require( '@stdlib/stats/incr/nancv' ); +* +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( NaN ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js new file mode 100644 index 000000000000..85e21d8d2756 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var incrcv = require( '@stdlib/stats/incr/cv' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring NaN values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( NaN ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +*/ +function incrnancv() { + var cv = incrcv(); + + /** + * If provided a value, the accumulator function returns an updated accumulated value. + * If not provided a value, the accumulator function returns the current accumulated value. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} accumulated value or null + */ + function accumulator( x ) { + if ( arguments.length === 0 ) { + return cv(); + } + if ( isnan( x ) ) { + return cv(); + } + return cv( x ); + } + + return accumulator; +} + + +// EXPORTS // + +module.exports = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/package.json b/lib/node_modules/@stdlib/stats/incr/nancv/package.json new file mode 100644 index 000000000000..0f920daf9823 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/incr/nancv", + "version": "0.0.0", + "description": "Compute the coefficient of variation (CV) incrementally.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "stdev", + "std", + "variance", + "var", + "standard", + "deviation", + "dispersion", + "relative", + "rsd", + "cv", + "mean", + "ratio", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js new file mode 100644 index 000000000000..e01019857f84 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -0,0 +1,226 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var incrnancv = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnancv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnancv(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (known mean)', function test( t ) { + t.equal( typeof incrnancv( 3.0 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the coefficient of variation while ignoring NaN values', function test( t ) { + var expected; + var actual = []; + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, 4.0, NaN, 3.0, 4.0 ]; + + // Expected values ignoring NaNs: + expected = [ + 0.0 / (2.0 / 1.0), + 0.0 / (2.0 / 1.0), // NaN ignored + sqrt( 0.5 ) / (5.0 / 2.0), + sqrt( 0.33333333333333337 ) / (7.0 / 3.0), + sqrt( 0.9166666666666666 ) / (11.0 / 4.0), + sqrt( 0.9166666666666666 ) / (11.0 / 4.0), // NaN ignored + sqrt( 0.7 ) / (14.0 / 5.0), + sqrt( 0.8 ) / (18.0 / 6.0) + ]; + + acc = incrnancv(); + + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + t.deepEqual( actual, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current accumulated value', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 1.0 ]; + acc = incrnancv(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), sqrt( 1.0 ) / 2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current accumulated value (known mean, ignoring NaNs)', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 1.0, NaN ]; + acc = incrnancv( 2.0 ); + + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + + t.equal( acc(), 0.5, 'returns expected value while ignoring NaNs' ); + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (unknown mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (known mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv( 3.0 ); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 non-NaN datum has been provided', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'returns null' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `0` until at least 2 valid datums have been provided (unknown mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc( 2.0 ); + t.equal( cv, 0.0, 'returns 0' ); + + cv = acc(); + t.equal( cv, 0.0, 'returns 0' ); + + cv = acc( NaN ); + t.equal( cv, 0.0, 'still returns 0 after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, 0.0, 'does not return 0 after two valid numbers' ); + + cv = acc(); + t.notEqual( cv, 0.0, 'does not return 0' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it and continues accumulating valid values (unknown mean)', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ 2.0, NaN, 1.0, NaN, 2.0, 3.0, NaN, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnancv(); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.notEqual( isnan( v ), true, 'does not return NaN' ); + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + } + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it and continues accumulating valid values (known mean)', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ 2.0, NaN, 1.0, NaN, 2.0, 3.0, NaN, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnancv( 3.14 ); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.notEqual( isnan( v ), true, 'does not return NaN' ); + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + } + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + t.end(); +});