From ba26eca1f94382d1b56fbb8d5c8a90aa75b31aa4 Mon Sep 17 00:00:00 2001 From: impawstarlight Date: Fri, 14 Mar 2025 21:35:19 +0600 Subject: [PATCH 1/4] feat(stats): add nanskewness package --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanskewness/README.md | 215 ++++++++++++++++++ .../incr/nanskewness/benchmark/benchmark.js | 69 ++++++ .../img/equation_adjusted_sample_skewness.svg | 171 ++++++++++++++ .../docs/img/equation_sample_skewness.svg | 131 +++++++++++ .../docs/img/equation_skewness.svg | 59 +++++ .../stats/incr/nanskewness/docs/repl.txt | 33 +++ .../incr/nanskewness/docs/types/index.d.ts | 62 +++++ .../stats/incr/nanskewness/docs/types/test.ts | 61 +++++ .../stats/incr/nanskewness/examples/index.js | 48 ++++ .../stats/incr/nanskewness/lib/index.js | 57 +++++ .../stats/incr/nanskewness/lib/main.js | 84 +++++++ .../stats/incr/nanskewness/package.json | 65 ++++++ .../stats/incr/nanskewness/test/test.js | 122 ++++++++++ 13 files changed, 1177 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_adjusted_sample_skewness.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_sample_skewness.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/img/equation_skewness.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js 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..91b9db2567dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md @@ -0,0 +1,215 @@ + + +# incrnanskewness + +> Compute a [corrected sample skewness][sample-skewness] incrementally, ignoring `NaN` values. + +
+ +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/nanskewness' ); +``` + +#### incrnanskewness() + +Returns an accumulator `function` which incrementally computes a [corrected sample skewness][sample-skewness], ignoring `NaN` values. + +```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(); +// returns ~0.492 + +skewness = accumulator(NaN); +// 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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanskewness = require( '@stdlib/stats/incr/nanskewness' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanskewness(); + +// For each simulated datum, update the corrected sample skewness... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + +* * * + +
+ +
+ + + + + + + + + + + + + + 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..3d123502f012 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @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 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..fbe8eacc586b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a corrected + sample skewness, ingoring `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. + + If provided `NaN` or a value which, when used in computations, results in + `NaN`, the accumulated value is `NaN` for all future invocations. + + 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() + ~0.492 + > v = accumulator(NaN) + ~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..33d357c33f53 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/index.d.ts @@ -0,0 +1,62 @@ +/* +* @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. +* +* @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, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* 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(); +* // returns ~0.492 +* +* skewness = accumulator(NaN); +* // returns ~0.492 +*/ +declare function incrnanskewness(): accumulator; + + +// EXPORTS // + +export = incrnanskewness; 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..4d8f56dea867 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js @@ -0,0 +1,48 @@ +/** +* @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 incrnanskewness = require( './../lib' ); + +var accumulator; +var skewness; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanskewness(); + +// For each simulated datum, update the corrected sample 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 ); + if ( skewness === null ) { + console.log( '%d\t%s', v.toFixed( 4 ), skewness ); + } else { + console.log( '%d\t%d', v.toFixed( 4 ), skewness.toFixed( 4 ) ); + } +} +console.log( '\nFinal skewness: %d\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..788f7c5aabce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 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(); +* // returns ~0.492 +* +* skewness = accumulator(NaN); +* // 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..32bcacf7522f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js @@ -0,0 +1,84 @@ +/** +* @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 incrskewness = require( '@stdlib/stats/incr/skewness' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a corrected sample skewness, ignoring `NaN` values. +* +* ## Method +* +* The algorithm computes the corrected sample skewness using the formula for `G_1` in [Joanes and Gill 1998][@joanes:1998]. +* +* ## 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 = 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 corrected sample skewness. If not provided a value, the accumulator function returns the current corrected sample skewness. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} corrected sample 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..053fda3d4e3f --- /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, 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", + "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..845d9f5ab672 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js @@ -0,0 +1,122 @@ +/** +* @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 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 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, NaN, -1.0, NaN, 9.0 ]; + + // Check against the skewness function of the `e1071` R package: + expected = [ + null, + null, + 1.457862967321305, + 1.457862967321305, + 0.4366620845757488, + 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, NaN, 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( NaN ); + t.equal( skewness, null, 'returns null' ); + + skewness = acc( 3.0 ); + t.notEqual( skewness, null, 'does not return null' ); + + t.end(); +}); From c1721635922d37a9fe6925e111ae228245c6ee25 Mon Sep 17 00:00:00 2001 From: impawstarlight Date: Fri, 14 Mar 2025 22:48:25 +0600 Subject: [PATCH 2/4] chore: edit comments to reflect package functionality --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanskewness/docs/repl.txt | 3 --- .../@stdlib/stats/incr/nanskewness/lib/main.js | 10 ---------- 2 files changed, 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt index fbe8eacc586b..eb9abadc651b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt @@ -7,9 +7,6 @@ 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 ------- acc: Function diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js index 32bcacf7522f..a16f2385131a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js @@ -29,16 +29,6 @@ var incrskewness = require( '@stdlib/stats/incr/skewness' ); /** * Returns an accumulator function which incrementally computes a corrected sample skewness, ignoring `NaN` values. * -* ## Method -* -* The algorithm computes the corrected sample skewness using the formula for `G_1` in [Joanes and Gill 1998][@joanes:1998]. -* -* ## 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 From b4493b9b1db69684a93000ee0c0c5789621351ab Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:52:39 +0000 Subject: [PATCH 3/4] chore: update copyright years --- .../@stdlib/stats/incr/nanskewness/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanskewness/docs/types/test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 33d357c33f53..856b314eec66 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. 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 index a2ef30a7fa56..9f60c23e7bd7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. From b148617fc8e80bec72015422f51efb90c40749d3 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 17 Mar 2025 21:44:38 -0700 Subject: [PATCH 4/4] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanskewness/README.md | 49 +++---------------- .../stats/incr/nanskewness/docs/repl.txt | 14 +++--- .../incr/nanskewness/docs/types/index.d.ts | 8 ++- .../stats/incr/nanskewness/examples/index.js | 22 ++++----- .../stats/incr/nanskewness/lib/index.js | 4 +- .../stats/incr/nanskewness/lib/main.js | 5 +- .../stats/incr/nanskewness/test/test.js | 10 ++-- 7 files changed, 41 insertions(+), 71 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md b/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md index 91b9db2567dc..b6cb3f274099 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/README.md @@ -85,7 +85,7 @@ var incrnanskewness = require( '@stdlib/stats/incr/nanskewness' ); #### incrnanskewness() -Returns an accumulator `function` which incrementally computes a [corrected sample skewness][sample-skewness], ignoring `NaN` values. +Returns an accumulator function which incrementally computes a [corrected sample skewness][sample-skewness], ignoring `NaN` values. ```javascript var accumulator = incrnanskewness(); @@ -110,10 +110,10 @@ skewness = accumulator( -5.0 ); skewness = accumulator( -10.0 ); // returns ~0.492 -skewness = accumulator(); +skewness = accumulator( NaN ); // returns ~0.492 -skewness = accumulator(NaN); +skewness = accumulator(); // returns ~0.492 ``` @@ -138,24 +138,17 @@ skewness = accumulator(NaN); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var incrnanskewness = require( '@stdlib/stats/incr/nanskewness' ); -var accumulator; -var v; -var i; - // Initialize an accumulator: -accumulator = incrnanskewness(); +var accumulator = incrnanskewness(); // For each simulated datum, update the corrected sample skewness... +var i; for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { - v = NaN; - } else { - v = randu() * 100.0; - } - accumulator( v ); + accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) ); } console.log( accumulator() ); ``` @@ -164,8 +157,6 @@ console.log( accumulator() ); -* * * -
@@ -176,16 +167,6 @@ console.log( accumulator() ); @@ -196,20 +177,6 @@ console.log( accumulator() ); [sample-skewness]: https://en.wikipedia.org/wiki/Skewness - - -[@stdlib/stats/incr/kurtosis]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/kurtosis - -[@stdlib/stats/incr/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mean - -[@stdlib/stats/incr/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/stdev - -[@stdlib/stats/incr/summary]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/summary - -[@stdlib/stats/incr/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/variance - - - diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt index eb9abadc651b..7fe86cb98a03 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}() Returns an accumulator function which incrementally computes a corrected - sample skewness, ingoring `NaN` values. + 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 @@ -14,16 +14,16 @@ Examples -------- - > var accumulator = {{alias}}(); - > var v = accumulator( 2.0 ) + > var acc = {{alias}}(); + > var v = acc( 2.0 ) null - > v = accumulator( -5.0 ) + > v = acc( -5.0 ) null - > v = accumulator( -10.0 ) + > v = acc( -10.0 ) ~0.492 - > v = accumulator() + > v = acc( NaN ) ~0.492 - > v = accumulator(NaN) + > v = acc() ~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 index 856b314eec66..8e3cb39de9fa 100644 --- 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 @@ -31,6 +31,10 @@ type accumulator = ( x?: number ) => number | null; /** * Returns an accumulator function which incrementally computes a corrected sample skewness, ignoring `NaN` values. * +* ## 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. +* * @returns accumulator function * * @example @@ -48,10 +52,10 @@ type accumulator = ( x?: number ) => number | null; * skewness = accumulator( -10.0 ); * // returns ~0.492 * -* skewness = accumulator(); +* skewness = accumulator( NaN ); * // returns ~0.492 * -* skewness = accumulator(NaN); +* skewness = accumulator(); * // returns ~0.492 */ declare function incrnanskewness(): accumulator; diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js index 4d8f56dea867..4c167e7ae199 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/examples/index.js @@ -18,31 +18,27 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanskewness = require( './../lib' ); -var accumulator; -var skewness; -var v; -var i; - // Initialize an accumulator: -accumulator = incrnanskewness(); +var accumulator = incrnanskewness(); // For each simulated datum, update the corrected sample skewness... console.log( '\nValue\tSkewness\n' ); +var skewness; +var v; +var i; for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { - v = NaN; - } else { - v = randu() * 100.0; - } + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); skewness = accumulator( v ); if ( skewness === null ) { console.log( '%d\t%s', v.toFixed( 4 ), skewness ); } else { - console.log( '%d\t%d', v.toFixed( 4 ), skewness.toFixed( 4 ) ); + console.log( '%d\t%d', ( isnan( v ) ) ? NaN : v.toFixed( 4 ), skewness.toFixed( 4 ) ); } } console.log( '\nFinal skewness: %d\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 index 788f7c5aabce..8bd16488520c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/index.js @@ -40,10 +40,10 @@ * skewness = accumulator( -10.0 ); * // returns ~0.492 * -* skewness = accumulator(); +* skewness = accumulator( NaN ); * // returns ~0.492 * -* skewness = accumulator(NaN); +* skewness = accumulator(); * // returns ~0.492 */ diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js index a16f2385131a..a506f7b3ea57 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/lib/main.js @@ -32,7 +32,7 @@ var incrskewness = require( '@stdlib/stats/incr/skewness' ); * @returns {Function} accumulator function * * @example -* var accumulator = incrskewness(); +* var accumulator = incrnanskewness(); * * var skewness = accumulator(); * // returns null @@ -46,6 +46,9 @@ var incrskewness = require( '@stdlib/stats/incr/skewness' ); * skewness = accumulator( -10.0 ); * // returns ~0.492 * +* skewness = accumulator( NaN ); +* // returns ~0.492 +* * skewness = accumulator(); * // returns ~0.492 */ diff --git a/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js index 845d9f5ab672..a4144f3c5d71 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanskewness/test/test.js @@ -104,19 +104,19 @@ tape( 'the corrected sample skewness is `null` until at least 3 datums have been acc = incrnanskewness(); skewness = acc(); - t.equal( skewness, null, 'returns null' ); + t.equal( skewness, null, 'returns expected value' ); skewness = acc( 2.0 ); - t.equal( skewness, null, 'returns null' ); + t.equal( skewness, null, 'returns expected value' ); skewness = acc( 2.0 ); - t.equal( skewness, null, 'returns null' ); + t.equal( skewness, null, 'returns expected value' ); skewness = acc( NaN ); - t.equal( skewness, null, 'returns null' ); + t.equal( skewness, null, 'returns expected value' ); skewness = acc( 3.0 ); - t.notEqual( skewness, null, 'does not return null' ); + t.notEqual( skewness, null, 'returns expected value' ); t.end(); });