diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md b/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md new file mode 100644 index 000000000000..300bb91f0fc6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md @@ -0,0 +1,232 @@ + + +# incrnanskewness + +> Compute a [corrected sample skewness][sample-skewness] incrementally. + +
+ +The [skewness][sample-skewness] for a random variable `X` is defined as + + + +```math +\mathop{\mathrm{Skewness}}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^3 \biggr] +``` + + + + + +For a sample of `n` values, the [sample skewness][sample-skewness] is + + + +```math +b_1 = \frac{m_3}{s^3} = \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}} +``` + + + + + +where `m_3` is the sample third central moment and `s` is the sample standard deviation. + +An alternative definition for the [sample skewness][sample-skewness] which includes an adjustment factor (and is the implemented definition) is + + + +```math +G_1 = \frac{n^2}{(n-1)(n-2)} \frac{m_3}{s^3} = \frac{\sqrt{n(n-1)}}{n-2} \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanskewness = require( '@stdlib/stats/incr/skewness' ); +``` + +#### incrnanskewness() + +Returns an accumulator `function` which incrementally computes a [corrected sample skewness][sample-skewness]. + +```javascript +var accumulator = incrnanskewness(); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [corrected sample skewness][sample-skewness]. If not provided an input value `x`, the accumulator function returns the current [corrected sample skewness][sample-skewness]. + + + +```javascript +var accumulator = incrnanskewness(); + +var skewness = accumulator(); +// returns null + +skewness = accumulator(2.0); +// returns null + +skewness = accumulator(-5.0); +// returns null + +skewness = accumulator(-10.0); +// returns ~0.492 + +skewness = accumulator( NaN ); +// returns ~0.492 + +skewness = accumulator(); +// returns ~0.492 +``` + + + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. + +- For long running accumulations or accumulations of large numbers, care should be taken to prevent overflow. + +
+ + + +
+ +## Examples + + + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanskewness = require( '@stdlib/stats/incr/lib' ); + +var accumulator; +var skewness; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanskewness(); + +// For each simulated datum, update the skewness... +console.log('\nValue\tSkewness\n'); +for (i = 0; i < 100; i++) { + if (randu() < 0.2) { + v = NaN; + } else { + v = randu() * 100.0; + } + skewness = accumulator(v); + console.log( '%d\t%s', v.toFixed(4), (skewness === null) ? 'NaN' : skewness.toFixed(4)); +} +console.log('\nFinal skewness: %s\n', accumulator()); +``` + + + +
+ + + +* * * + +
+ +## References + +- Joanes, D. N., and C. A. Gill. 1998. "Comparing measures of sample skewness and kurtosis." +- Journal of the Royal Statistical Society: Series D (The Statistician)_ 47 (1). Blackwell Publishers Ltd: 183–89. doi:[10.1111/1467-9884.00122][@joanes:1998]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/benchmark/benchmark.js new file mode 100644 index 000000000000..8117c341a953 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 incrnanskewness = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanskewness(); + 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 = incrnanskewness(); + + 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/nanskewness/docs/img/equation_adjusted_sample_skewness.svg b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_adjusted_sample_skewness.svg new file mode 100644 index 000000000000..3277353af222 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_adjusted_sample_skewness.svg @@ -0,0 +1,171 @@ + +upper G 1 equals StartFraction n squared Over left-parenthesis n minus 1 right-parenthesis left-parenthesis n minus 2 right-parenthesis EndFraction StartFraction m 3 Over s cubed EndFraction equals StartFraction StartRoot n left-parenthesis n minus 1 right-parenthesis EndRoot Over n minus 2 EndFraction StartStartFraction StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis cubed OverOver left-parenthesis StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared right-parenthesis Superscript 3 slash 2 Baseline EndEndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_sample_skewness.svg b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_sample_skewness.svg new file mode 100644 index 000000000000..147334d80f8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_sample_skewness.svg @@ -0,0 +1,131 @@ + +b 1 equals StartFraction m 3 Over s cubed EndFraction equals StartStartFraction StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis cubed OverOver left-parenthesis StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared right-parenthesis Superscript 3 slash 2 Baseline EndEndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_skewness.svg b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_skewness.svg new file mode 100644 index 000000000000..45650ae35b70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_skewness.svg @@ -0,0 +1,59 @@ + +upper S k e w n e s s left-bracket upper X right-bracket equals normal upper E left-bracket left-parenthesis StartFraction upper X minus mu Over sigma EndFraction right-parenthesis cubed right-bracket + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt new file mode 100644 index 000000000000..d6d6b7542e3c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a corrected + sample skewness, ignoring NaN values. + + If provided a value, the accumulator function returns an updated corrected + sample skewness. If not provided a value, the accumulator function returns + the current corrected sample skewness. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var v = accumulator( 2.0 ) + null + > v = accumulator( -5.0 ) + null + > v = accumulator( -10.0 ) + ~0.492 + > v = accumulator( NaN ) + ~0.492 + > v = accumulator() + ~0.492 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/index.d.ts new file mode 100644 index 000000000000..384d6311795e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/index.d.ts @@ -0,0 +1,68 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 corrected sample skewness. If not provided a value, the accumulator function returns the current corrected sample skewness. +* +* ## 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 corrected sample skewness or null +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a corrected sample skewness. +* +* ## Notes +* +* - If provided a value, the accumulator function returns an updated corrected sample skewness. If not provided a value, the accumulator function returns the current corrected sample skewness. +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* +* @returns accumulator function +* +* @example +* var accumulator = incrskewness(); +* +* var skewness = accumulator(); +* // returns null +* +* skewness = accumulator( 2.0 ); +* // returns null +* +* skewness = accumulator( -5.0 ); +* // returns null +* +* skewness = accumulator( -10.0 ); +* // returns ~0.492 +* +* skewness = accumulator(); +* // returns ~0.492 +*/ +declare function incrskewness(): accumulator; + + +// EXPORTS // + +export = incrskewness; diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts new file mode 100644 index 000000000000..a2ef30a7fa56 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 incrnanskewness = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanskewness(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + incrnanskewness( '5' ); // $ExpectError + incrnanskewness( true ); // $ExpectError + incrnanskewness( false ); // $ExpectError + incrnanskewness( null ); // $ExpectError + incrnanskewness( [] ); // $ExpectError + incrnanskewness( {} ); // $ExpectError + incrnanskewness( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanskewness(); + + acc(); // $ExpectType number | null + acc( 2 ); // $ExpectType number | null + acc( -5 ); // $ExpectType number | null + acc( 10 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanskewness(); + + 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/nanskewness/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js new file mode 100644 index 000000000000..88b03efd4ff1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 incrnanskewness = require( './../lib' ); + +var accumulator; +var skewness; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanskewness(); + +// For each simulated datum, update the skewness... +console.log( '\nValue\tSkewness\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + skewness = accumulator( v ); + console.log( '%d\t%s', v.toFixed( 4 ), ( skewness === null ) ? 'NaN' : skewness.toFixed( 4 ) ); +} +console.log( '\nFinal skewness: %s\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js new file mode 100644 index 000000000000..978dd6185a95 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 a skewness incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanskewness +* +* @example +* var incrnanskewness = require( '@stdlib/stats/incr/nanskewness' ); +* +* var accumulator = incrnanskewness(); +* +* var skewness = accumulator(); +* // returns null +* +* skewness = accumulator( 2.0 ); +* // returns null +* +* skewness = accumulator( -5.0 ); +* // returns null +* +* skewness = accumulator( -10.0 ); +* // returns ~0.492 +* +* skewness = accumulator( NaN ); +* // returns ~0.492 +* +* skewness = accumulator(); +* // returns ~0.492 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js new file mode 100644 index 000000000000..0d5ddf1af93f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrskewness = require( '@stdlib/stats/incr/skewness' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes skewness, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrskewness(); + +* var skewness = accumulator(); +* // returns null + +* skewness = accumulator( 2.0 ); +* // returns null + +* skewness = accumulator( -5.0 ); +* // returns null + +* skewness = accumulator( -10.0 ); +* // returns ~0.492 + +* skewness = accumulator(); +* // returns ~0.492 +*/ +function incrnanskewness() { + var skewness = incrskewness(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated skewness. If not provided a value, the accumulator function returns the current skewness. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} skewness or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return skewness(); + } + return skewness( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanskewness; diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/package.json b/lib/node_modules/@stdlib/stats/incr/nanskewness/package.json new file mode 100644 index 000000000000..7f14e4f6a707 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/incr/nanskewness", + "version": "0.0.0", + "description": "Compute a corrected sample skewness 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", + "skewness", + "sample skewness", + "shape", + "corrected", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js new file mode 100644 index 000000000000..b276b10650d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js @@ -0,0 +1,149 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanskewness = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanskewness, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanskewness(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanskewness(); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a corrected sample skewness', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ 3.0, 2.0, 7.0, -1.0, 9.0 ]; + + // Check against the skewness function of the `e1071` R package: + expected = [ + null, + null, + 1.457862967321305, + 0.4366620845757488, + 0.1171875 + ]; + + acc = incrnanskewness(); + for ( i = 0; i < data.length; i++ ) { + actual = acc( data[ i ] ); + if ( expected[ i ] === null ) { + t.equal( actual, expected[i], 'returns null' ); + } else { + delta = abs( actual - expected[ i ] ); + tol = 1.5 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. E: '+expected[i]+' Δ: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current corrected sample skewness', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ 1.0, 4.0, 1.0, 0.0, 2.0, 12.0 ]; + acc = incrnanskewness(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + expected = 1.986829609590966; + actual = acc(); + delta = abs( actual - expected ); + tol = EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.end(); +}); + +tape( 'the corrected sample skewness is `null` until at least 3 datums have been provided', function test( t ) { + var skewness; + var acc; + + acc = incrnanskewness(); + + skewness = acc(); + t.equal( skewness, null, 'returns null' ); + + skewness = acc( 2.0 ); + t.equal( skewness, null, 'returns null' ); + + skewness = acc( 2.0 ); + t.equal( skewness, null, 'returns null' ); + + skewness = acc( 3.0 ); + t.notEqual( skewness, null, 'does not return null' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores the `NaN` and returns current skewness', function test( t ) { + var data; + var nan = 2; + var acc; + var v; + var i; + + data = [ NaN, 2.0, 1.0, -2.0, -3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnanskewness(); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( isnan( data[i] ) ) { + t.equal( v, acc(), 'ignores NaN and returns current skewness' ); + } else if ( nan > 0 ) { + t.equal( v, null, 'initial non NaN values are null' ); + nan -= 1; + } + else { + t.equal( typeof v, 'number', 'returns a number' ); + } + } + + t.end(); +});