diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/README.md b/lib/node_modules/@stdlib/stats/incr/nankurtosis/README.md new file mode 100644 index 000000000000..6c5a1a45d8c7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/README.md @@ -0,0 +1,217 @@ + + +# incrnankurtosis + +> Compute a [corrected sample excess kurtosis][sample-excess-kurtosis] incrementally, ignoring `NaN` values. + +
+ +The [kurtosis][sample-excess-kurtosis] for a random variable `X` is defined as + + + +```math +\mathop{\mathrm{Kurtosis}}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^4 \biggr] +``` + + + + + +Using a univariate normal distribution as the standard of comparison, the [excess kurtosis][sample-excess-kurtosis] is the kurtosis minus `3`. + +For a sample of `n` values, the [sample excess kurtosis][sample-excess-kurtosis] is + + + +```math +g_2 = \frac{m_4}{m_2^2} - 3 = \frac{\frac{1}{n} \displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\frac{1}{n} \displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2} +``` + + + + + +where `m_4` is the sample fourth central moment and `m_2` is the sample second central moment. + +The previous equation is, however, a biased estimator of the population excess kurtosis. An alternative estimator which is unbiased under normality is + + + +```math +G_2 = \frac{(n+1)n}{(n-1)(n-2)(n-3)} \frac{\displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2} - 3 \frac{(n-1)^2}{(n-2)(n-3)} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnankurtosis = require( '@stdlib/stats/incr/nankurtosis' ); +``` + +#### incrnankurtosis() + +Returns an accumulator function which incrementally computes a [corrected sample excess kurtosis][sample-excess-kurtosis], ignoring `NaN` values. + +```javascript +var accumulator = incrnankurtosis(); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [corrected sample excess kurtosis][sample-excess-kurtosis]. If not provided an input value `x`, the accumulator function returns the current [corrected sample excess kurtosis][sample-excess-kurtosis]. + +```javascript +var accumulator = incrnankurtosis(); + +var kurtosis = accumulator( 2.0 ); +// returns null + +kurtosis = accumulator( 2.0 ); +// returns null + +kurtosis = accumulator( -4.0 ); +// returns null + +kurtosis = accumulator( -4.0 ); +// returns -6.0 + +kurtosis = accumulator( NaN ); +// returns -6.0 +``` + +
+ + + +
+ +## Notes + +- Input values are type checked. If non-numaric input are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnankurtosis = require( '@stdlib/stats/incr/nankurtosis' ); + +var accumulator; +var kurtosis; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnankurtosis(); + +// For each simulated datum, update the corrected sample excess kurtosis... +for ( i = 0; i < 100; i++ ) { + v = (randu() < 0.2 ) ? NaN : randu() * 100.0; // 20% chance of NaN + kurtosis = accumulator( v ); +} +console.log( 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/nankurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nankurtosis/benchmark/benchmark.js new file mode 100644 index 000000000000..67e1871b203f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/benchmark/benchmark.js @@ -0,0 +1,68 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var incrnankurtosis = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnankurtosis(); + 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 = incrnankurtosis(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( i ); + 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/nankurtosis/docs/img/equation_corrected_sample_excess_kurtosis.svg b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_corrected_sample_excess_kurtosis.svg new file mode 100644 index 000000000000..60f0e10c944d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_corrected_sample_excess_kurtosis.svg @@ -0,0 +1,153 @@ + +upper G 2 equals StartFraction left-parenthesis n plus 1 right-parenthesis n Over left-parenthesis n minus 1 right-parenthesis left-parenthesis n minus 2 right-parenthesis left-parenthesis n minus 3 right-parenthesis EndFraction StartFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis Superscript 4 Baseline Over left-parenthesis 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 squared EndFraction minus 3 StartFraction left-parenthesis n minus 1 right-parenthesis squared Over left-parenthesis n minus 2 right-parenthesis left-parenthesis n minus 3 right-parenthesis EndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_kurtosis.svg b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_kurtosis.svg new file mode 100644 index 000000000000..49e80f11cb5b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_kurtosis.svg @@ -0,0 +1,60 @@ + +upper K u r t o s i 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 Superscript 4 Baseline right-bracket + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_sample_excess_kurtosis.svg b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_sample_excess_kurtosis.svg new file mode 100644 index 000000000000..e9c08dadc077 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/img/equation_sample_excess_kurtosis.svg @@ -0,0 +1,125 @@ + +g 2 equals StartFraction m 4 Over m 2 squared EndFraction minus 3 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 Superscript 4 Baseline 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 squared EndEndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/repl.txt new file mode 100644 index 000000000000..bb4ec23ea2ef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a corrected + sample excess kurtosis, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated corrected + sample excess kurtosis. If not provided a value, the accumulator function + returns the current corrected sample excess kurtosis. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var v = accumulator( 2.0 ) + null + > v = accumulator( 2.0 ) + null + > v = accumulator( -4.0 ) + null + > v = accumulator( -4.0 ) + -6.0 + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/index.d.ts new file mode 100644 index 000000000000..5e3481a476e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/index.d.ts @@ -0,0 +1,62 @@ +/* +* @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, returns an updated corrected sample excess kurtosis; otherwise, returns the current corrected sample excess kurtosis, ignoring `NaN` values. +* +* @param x - value +* @returns corrected sample excess kurtosis +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a corrected sample excess kurtosis. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnankurtosis(); +* +* var kurtosis = accumulator(); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( NaN ); +* // returns -6.0 +*/ +declare function incrnankurtosis(): accumulator; + + +// EXPORTS // + +export = incrnankurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/test.ts new file mode 100644 index 000000000000..1684d3ede818 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @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 incrnankurtosis = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnankurtosis(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnankurtosis( '5' ); // $ExpectError + incrnankurtosis( 5 ); // $ExpectError + incrnankurtosis( true ); // $ExpectError + incrnankurtosis( false ); // $ExpectError + incrnankurtosis( null ); // $ExpectError + incrnankurtosis( undefined ); // $ExpectError + incrnankurtosis( [] ); // $ExpectError + incrnankurtosis( {} ); // $ExpectError + incrnankurtosis( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnankurtosis(); + + 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 = incrnankurtosis(); + + 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/nankurtosis/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nankurtosis/examples/index.js new file mode 100644 index 000000000000..6a649667e717 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 incrkurtosis = require( './../lib' ); + +var accumulator; +var kurtosis; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrkurtosis(); + +// For each simulated datum, update the corrected sample excess kurtosis... +console.log( '\nValue\tKurtosis\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( randu() < 0.2 ) ? NaN : randu() * 100.0; // 20% chance of `NaN` + kurtosis = accumulator( v ); + if ( i < 3 ) { + console.log( '%d\t%s', v.toFixed( 4 ), kurtosis ); + } else { + console.log( '%d\t%d', v.toFixed( 4 ), ( kurtosis === null ) ? kurtosis : kurtosis.toFixed( 4 ) ); + } +} +console.log( '\nFinal excess kurtosis: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nankurtosis/lib/index.js new file mode 100644 index 000000000000..b84bd211dc96 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/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 a corrected sample excess kurtosis incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nankurtosis +* +* @example +* var incrnankurtosis = require( '@stdlib/stats/incr/nankurtosis' ); +* +* var accumulator = incrnankurtosis(); +* +* var kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( NaN ); +* // returns -6.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nankurtosis/lib/main.js new file mode 100644 index 000000000000..799b79066367 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrkurtosis = require( '@stdlib/stats/incr/kurtosis/lib' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a corrected sample excess kurtosis, ignoring `NaN` values. +* +* ## Method +* +* The algorithm computes the sample excess kurtosis using the formula for `G_2` in [Joanes and Gill 1998][@joanes:1998]. In contrast to alternatives for calculating a sample kurtosis, `G_2` is an unbiased estimator under normality. +* +* ## 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]. +* +* [@joanes:1998]: http://dx.doi.org/10.1111/1467-9884.00122 +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrkurtosis(); +* +* var kurtosis = accumulator(); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( NaN ); +* // returns -6.0 +*/ +function incrnankurtosis() { + var kurtosis = incrkurtosis(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated corrected sample excess kurtosis. If not provided a value, the accumulator function returns the current corrected sample excess kurtosis. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} corrected sample excess kurtosis + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return kurtosis(); + } + return kurtosis( x ); + } +} + + +// EXPORTS // + +module.exports = incrnankurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/package.json b/lib/node_modules/@stdlib/stats/incr/nankurtosis/package.json new file mode 100644 index 000000000000..3aa1157edde1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/stats/incr/nankurtosis", + "version": "0.0.0", + "description": "Compute a corrected sample excess kurtosis incrementally, ignoring NaN values.", + "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", + "kurtosis", + "sample kurtosis", + "shape", + "kurt", + "corrected", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nankurtosis/test/test.js b/lib/node_modules/@stdlib/stats/incr/nankurtosis/test/test.js new file mode 100644 index 000000000000..47b17775a456 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nankurtosis/test/test.js @@ -0,0 +1,118 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnankurtosis = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnankurtosis, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnankurtosis(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a corrected sample excess kurtosis', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 2.0, NaN, 2.0, -4.0, -4.0, 1.5, NaN, -10 ]; + + // Check against the kurtosis function of the `e1071` R package: + expected = [ + null, + null, + null, + null, + -6, + -3.309339678762642, + -3.309339678762642, + -0.1906596382525679 + ]; + + acc = incrnankurtosis(); + + for ( i = 0; i < data.length; i++ ) { + actual = acc( data[ i ] ); + if ( expected[i] === null ) { + t.equal( actual, null, '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 excess kurtosis', function test( t ) { + var data; + var acc; + var i; + + data = [ -10.0, NaN, -10.0, 10.0, NaN, 10.0 ]; + acc = incrnankurtosis(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + + t.equal( acc(), -6.0, 'returns the current accumulated corrected sample excess kurtosis' ); + t.end(); +}); + +tape( 'the corrected sample excess kurtosis is `null` until at least 4 datums have been provided', function test( t ) { + var acc; + var out; + + acc = incrnankurtosis(); + + out = acc(); + t.equal( out, null, 'returns null' ); + + out = acc( 2.0 ); + t.equal( out, null, 'returns null' ); + + out = acc( 8.0 ); + t.equal( out, null, 'returns null' ); + + out = acc( -4.0 ); + t.equal( out, null, 'returns null' ); + + out = acc( 3.0 ); + t.notEqual( out, null, 'does not return null' ); + + t.end(); +});