From 808448e38d28495a84d05c03b5af30d1699f8604 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 09:44:18 +0000 Subject: [PATCH 1/6] feat: add `stats/base/ztest/two-sample/results/struct-factory` --- 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 --- --- .../results/struct-factory/README.md | 152 +++++++++++++++ .../struct-factory/benchmark/benchmark.js | 54 ++++++ .../results/struct-factory/docs/repl.txt | 25 +++ .../struct-factory/docs/types/index.d.ts | 179 ++++++++++++++++++ .../results/struct-factory/docs/types/test.ts | 56 ++++++ .../results/struct-factory/examples/index.js | 58 ++++++ .../results/struct-factory/lib/index.js | 43 +++++ .../results/struct-factory/lib/main.js | 99 ++++++++++ .../results/struct-factory/package.json | 65 +++++++ .../results/struct-factory/test/test.js | 151 +++++++++++++++ 10 files changed, 882 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/README.md new file mode 100644 index 000000000000..b1ab9f692cc9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/README.md @@ -0,0 +1,152 @@ + + +# structFactory + +> Create a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); +``` + +#### structFactory( dtype ) + +Returns a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + +```javascript +var Struct = structFactory( 'float64' ); +// returns + +var s = new Struct(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`. + +
+ + + + + +
+ +## Notes + +- A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing two-sample Z-test results and provides an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); + +var Struct = structFactory( 'float64' ); +var results = new Struct({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +results = new Struct({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/benchmark/benchmark.js new file mode 100644 index 000000000000..f4c4a1b9ec96 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/benchmark/benchmark.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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( values[ i%values.length ] ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/repl.txt new file mode 100644 index 000000000000..20a4d663e618 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( dtype ) + Returns a new struct constructor tailored to a specified floating-point data + type. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point results. + + Returns + ------- + fcn: Function + Struct constructor. + + Examples + -------- + > var S = {{alias}}( 'float64' ); + > var r = new S(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts new file mode 100644 index 000000000000..ef4c3df34fe4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts @@ -0,0 +1,179 @@ +/* +* @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 + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: number; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: T; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue?: number; + + /** + * Standard error of the mean. + */ + sd?: number; +} + +/** +* Interface describing a struct data structure. +*/ +declare class Struct { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: number; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: T; + + /** + * Value of the mean under the null hypothesis + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; +} + +/** +* Interface defining a struct constructor which is both "newable" and "callable". +*/ +interface StructConstructor { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): Struct; + + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): Struct; +} + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float64' ): StructConstructor; + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float32' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float32' ): StructConstructor; + + +// EXPORTS // + +export = structFactory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/test.ts new file mode 100644 index 000000000000..dd8f7ba98f06 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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 structFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + structFactory( 'float64' ); // $ExpectType StructConstructor + structFactory( 'float32' ); // $ExpectType StructConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + structFactory( 10 ); // $ExpectError + structFactory( true ); // $ExpectError + structFactory( false ); // $ExpectError + structFactory( null ); // $ExpectError + structFactory( undefined ); // $ExpectError + structFactory( [] ); // $ExpectError + structFactory( {} ); // $ExpectError + structFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a struct object... +{ + const Struct = structFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s1 = new Struct( new ArrayBuffer( 80 ) ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s2 = new Struct( new ArrayBuffer( 80 ), 8 ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s3 = new Struct( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType Struct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/examples/index.js new file mode 100644 index 000000000000..8e90512d0bd8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/examples/index.js @@ -0,0 +1,58 @@ +/** +* @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 resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var structFactory = require( './../lib' ); + +var Struct = structFactory( 'float64' ); +var results = new Struct({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +results = new Struct({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/index.js new file mode 100644 index 000000000000..6192dae6b83d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/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'; + +/** +* Create a new struct constructor tailored to a specified floating-point data type. +* +* @module @stdlib/stats/base/ztest/two-sample/results/struct-factory +* +* @example +* var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); +* +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/main.js new file mode 100644 index 000000000000..f7b2d62b9f17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/lib/main.js @@ -0,0 +1,99 @@ +/** +* @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 struct = require( '@stdlib/dstructs/struct' ); + + +// MAIN // + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param {string} dtype - floating-point data type +* @returns {Function} struct constructor +* +* @example +* var Struct = factory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +function factory( dtype ) { + var schema = [ + { + 'name': 'rejected', + 'description': 'boolean indicating whether the null hypothesis was rejected', + 'type': 'bool', + 'castingMode': 'none' + }, + { + 'name': 'alternative', + 'description': 'alternative hypothesis', + 'type': 'int8', + 'castingMode': 'none' + }, + { + 'name': 'alpha', + 'description': 'significance level', + 'type': dtype, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'pValue', + 'description': 'p-value', + 'type': dtype, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'statistic', + 'description': 'test statistic', + 'type': dtype, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'ci', + 'description': 'confidence interval', + 'type': dtype, + 'length': 2, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'nullValue', + 'description': 'null value', + 'type': dtype, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'sd', + 'description': 'standard error of the mean', + 'type': dtype, + 'castingMode': 'mostly-safe' + } + ]; + return struct( schema ); +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/package.json new file mode 100644 index 000000000000..c065f7c62683 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/struct-factory", + "version": "0.0.0", + "description": "Create a new struct constructor tailored to a specified floating-point data type.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "struct", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/test/test.js new file mode 100644 index 000000000000..4cb77838f2ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/test/test.js @@ -0,0 +1,151 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var structFactory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof structFactory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + structFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float64)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float64' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) + }); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float32)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float32' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) + }); + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': resolveEnum( 'two-sided' ) + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); From b1fa4b66fe769590ba205190394059fbd7b4d0c8 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 11:42:50 +0000 Subject: [PATCH 2/6] feat: add `stats/base/ztest/two-sample/results/factory` --- 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 --- --- .../two-sample/results/factory/README.md | 151 +++++ .../results/factory/benchmark/benchmark.js | 105 ++++ .../two-sample/results/factory/docs/repl.txt | 24 + .../results/factory/docs/types/index.d.ts | 189 ++++++ .../results/factory/docs/types/test.ts | 56 ++ .../results/factory/examples/index.js | 57 ++ .../two-sample/results/factory/lib/index.js | 55 ++ .../two-sample/results/factory/lib/main.js | 268 +++++++++ .../two-sample/results/factory/package.json | 66 ++ .../two-sample/results/factory/test/test.js | 563 ++++++++++++++++++ 10 files changed, 1534 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md new file mode 100644 index 000000000000..6c96354d4b13 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md @@ -0,0 +1,151 @@ + + +# resultsFactory + +> Create a new constructor for creating a two-sample Z-test results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); +``` + +#### resultsFactory( dtype ) + +Returns a new constructor for creating a two-sample Z-test results object. + +```javascript +var Results = resultsFactory( 'float64' ); +// returns + +var r = new Results(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`. + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + +var Results = resultsFactory( 'float64' ); +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Results = resultsFactory( 'float32' ); +results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js new file mode 100644 index 000000000000..70e54338bd20 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( values[ i%values.length ] ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,new', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new ( values[ i%values.length ] )(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ](); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt new file mode 100644 index 000000000000..24564f0d59a9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( dtype ) + Returns a constructor for creating a two-sample Z-test results object. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point results. + + Returns + ------- + fcn: Function + Constructor. + + Examples + -------- + > var R = {{alias}}( 'float64' ); + > var r = new R(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts new file mode 100644 index 000000000000..abcf2cb457cd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts @@ -0,0 +1,189 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: T; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue?: number; + + /** + * Standard error of the mean. + */ + sd?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: T; + + /** + * Value of the mean under the null hypothesis + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a new results constructor for creating a two-sample Z-test results object. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns results constructor +* +* @example +* var Results = resultsFactory( 'float64' ); +* // returns +* +* var r = new Results(); +* // returns +*/ +declare function resultsFactory( dtype: 'float64' ): ResultsConstructor; + +/** +* Returns a constructor for creating a two-sample Z-test results object. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns results constructor +* +* @example +* var Results = resultsFactory( 'float32' ); +* // returns +* +* var r = new Results(); +* // returns +*/ +declare function resultsFactory( dtype: 'float32' ): ResultsConstructor; + + +// EXPORTS // + +export = resultsFactory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts new file mode 100644 index 000000000000..ace59c5ae4b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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 resultsFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + resultsFactory( 'float64' ); // $ExpectType ResultsConstructor + resultsFactory( 'float32' ); // $ExpectType ResultsConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + resultsFactory( 10 ); // $ExpectError + resultsFactory( true ); // $ExpectError + resultsFactory( false ); // $ExpectError + resultsFactory( null ); // $ExpectError + resultsFactory( undefined ); // $ExpectError + resultsFactory( [] ); // $ExpectError + resultsFactory( {} ); // $ExpectError + resultsFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a results object... +{ + const Results = resultsFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js new file mode 100644 index 000000000000..968f0d8390e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/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'; + +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resultsFactory = require( './../lib' ); + +var Results = resultsFactory( 'float64' ); +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Results = resultsFactory( 'float32' ); +results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js new file mode 100644 index 000000000000..d230fa906da1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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'; + +/** +* Return a constructor for creating a two-sample Z-test results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/factory +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); +* +* var Results = resultsFactory( 'float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float64Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js new file mode 100644 index 000000000000..10fe855ff407 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js @@ -0,0 +1,268 @@ +/** +* @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. +*/ + +/* eslint-disable no-invalid-this, no-restricted-syntax */ + +'use strict'; + +// MODULES // + +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' ); +var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var join = require( '@stdlib/array/base/join' ); +var objectAssign = require( '@stdlib/object/assign' ); +var inherit = require( '@stdlib/utils/inherit' ); +var resolveStr = require( '@stdlib/stats/base/ztest/alternative-resolve-str' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32' +]; + +var isDataType = contains( DTYPES ); + + +// MAIN // + +/** +* Returns a constructor for creating a two-sample Z-test results object. +* +* @param {string} dtype - storage data type for floating-point values +* @throws {TypeError} first argument must be a supported data type +* @returns {Function} constructor +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var Results = factory( 'float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float64Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ +function factory( dtype ) { + var alternativeDescriptor; + var Struct; + + if ( !isDataType( dtype ) ) { + throw new TypeError( format( 'invalid argument. First argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, ', ' ), dtype ) ); + } + + // Create a struct constructor: + Struct = structFactory( dtype ); + + // Cache a reference to a property descriptor on the parent prototype so that we can intercept the return value: + alternativeDescriptor = propertyDescriptor( Struct.prototype, 'alternative' ); + + /** + * Returns a two-sample Z-test results object. + * + * @private + * @constructor + * @param {(ArrayBuffer|Object)} [arg] - underlying byte buffer or a data object + * @param {NonNegativeInteger} [byteOffset] - byte offset + * @param {NonNegativeInteger} [byteLength] - maximum byte length + * @throws {TypeError} first argument must be an ArrayBuffer or a data object + * @returns {Results} results object + */ + function Results( arg, byteOffset, byteLength ) { + var nargs; + var args; + var v; + var i; + + nargs = arguments.length; + if ( !( this instanceof Results ) ) { + if ( nargs === 0 ) { + return new Results(); + } + if ( nargs === 1 ) { + return new Results( arg ); + } + if ( nargs === 2 ) { + return new Results( arg, byteOffset ); + } + return new Results( arg, byteOffset, byteLength ); + } + args = []; + if ( nargs > 0 ) { + if ( isArrayBuffer( arg ) ) { + for ( i = 0; i < nargs; i++ ) { + args.push( arguments[ i ] ); + } + } else if ( isObject( arg ) ) { + if ( hasProp( arg, 'alternative' ) ) { + args.push( objectAssign( {}, arg ) ); + v = resolveEnum( args[ 0 ].alternative ); + args[ 0 ].alternative = ( v === null ) ? NaN : v; + } + } else { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer or a data object. Value: `%s`.', arg ) ); + } + } + // Call the parent constructor... + Struct.apply( this, args ); + return this; + } + + /* + * Inherit from the parent constructor. + */ + inherit( Results, Struct ); + + /** + * Test name. + * + * @private + * @name method + * @memberof Results.prototype + * @type {string} + * @default 'Two-sample Z-test' + */ + setReadOnly( Results.prototype, 'method', 'Two-sample Z-test' ); + + /** + * Alternative hypothesis. + * + * @private + * @name alternative + * @memberof Results.prototype + * @type {string} + */ + setReadWriteAccessor( Results.prototype, 'alternative', getAlternative, setAlternative ); + + /** + * Serializes a results object as a string. + * + * ## Notes + * + * - Example output: + * + * ```text + * + * Two-sample Z-test + * + * Alternative hypothesis: True mean is less than 1.0 + * + * pValue: 0.0406 + * statistic: 9.9901 + * 95% confidence interval: [9.7821, 10.4451] + * + * Test Decision: Reject null in favor of alternative at 5% significance level + * + * ``` + * + * @private + * @name toString + * @memberof Results.prototype + * @type {Function} + * @param {Options} [opts] - options object + * @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point + * @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision + * @throws {TypeError} options argument must be an object + * @throws {TypeError} must provide valid options + * @returns {string} serialized results + */ + setReadOnly( Results.prototype, 'toString', function toString( opts ) { + if ( arguments.length ) { + return res2str( this, opts ); + } + return res2str( this ); + }); + + /** + * Serializes a results object as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Results` instance. + * + * @private + * @name toJSON + * @memberof Results.prototype + * @type {Function} + * @returns {Object} serialized object + */ + setReadOnly( Results.prototype, 'toJSON', function toJSON() { + return res2json( this ); + }); + + /** + * Returns a DataView of a results object. + * + * @private + * @name toDataView + * @memberof Results.prototype + * @type {Function} + * @returns {DataView} DataView + */ + setReadOnly( Results.prototype, 'toDataView', function toDataView() { + return Struct.viewOf( this ); + }); + + return Results; + + /** + * Returns the alternative hypothesis. + * + * @private + * @returns {string} alternative hypothesis + */ + function getAlternative() { + return resolveStr( alternativeDescriptor.get.call( this ) ); + } + + /** + * Sets the alternative hypothesis. + * + * @private + * @param {string} value - alternative hypothesis + */ + function setAlternative( value ) { + alternativeDescriptor.set.call( this, resolveEnum( value ) ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json new file mode 100644 index 000000000000..ec9dc34214af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/factory", + "version": "0.0.0", + "description": "Return a constructor for creating a two-sample Z-test results object.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js new file mode 100644 index 000000000000..0886401603bf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js @@ -0,0 +1,563 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var resultsFactory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof resultsFactory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + resultsFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided an invalid `alternative` property value', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results({ + 'alternative': value + }); + }; + } +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float64)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float32)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float32' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results({ + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (no arguments)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results(); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (empty object)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results( {} ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a method property', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toString` method', function test( t ) { + var Results; + var results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toJSON` method', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toDataView` method', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + + t.end(); +}); From 27e3905f3ece465ca21bc4105bfe195da0ff4e60 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 11:50:35 +0000 Subject: [PATCH 3/6] feat: add `stats/base/ztest/two-sample/results/float64` --- 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 --- --- .../two-sample/results/float64/README.md | 410 ++++++++++++++++++ .../results/float64/benchmark/benchmark.js | 70 +++ .../two-sample/results/float64/docs/repl.txt | 29 ++ .../results/float64/docs/types/index.d.ts | 187 ++++++++ .../results/float64/docs/types/test.ts | 39 ++ .../results/float64/examples/index.js | 38 ++ .../base/ztest/two-sample/results/float64.h | 54 +++ .../two-sample/results/float64/lib/index.js | 53 +++ .../two-sample/results/float64/lib/main.js | 62 +++ .../two-sample/results/float64/manifest.json | 36 ++ .../two-sample/results/float64/package.json | 67 +++ .../two-sample/results/float64/test/test.js | 408 +++++++++++++++++ 12 files changed, 1453 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md new file mode 100644 index 000000000000..89b29de1036f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md @@ -0,0 +1,410 @@ + + +# Float64Results + +> Create a two-sample Z-test double-precision floating-point results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +``` + +#### Float64Results( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns a two-sample Z-test double-precision floating-point results object. + +```javascript +var results = new Float64Results(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **rejected**: boolean indicating whether the null hypothesis was rejected. +- **alternative**: the alternative hypothesis (e.g., `'two-sided'`, `'less'`, or `'greater'`). +- **alpha**: significance level. +- **pValue**: p-value. +- **statistic**: test statistic. +- **ci**: confidence interval as a [`Float64Array`][@stdlib/array/float64]. +- **nullValue**: mean under the null hypothesis. +- **sd**: standard error of the mean. + +#### Float64Results.prototype.rejected + +Boolean indicating whether the null hypothesis was rejected. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.rejected; +// returns +``` + +#### Float64Results.prototype.alternative + +The alternative hypothesis. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.alternative; +// returns +``` + +#### Float64Results.prototype.alpha + +Significance level. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.alpha; +// returns +``` + +#### Float64Results.prototype.pValue + +The test p-value. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.pValue; +// returns +``` + +#### Float64Results.prototype.statistic + +The test statistic. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.statistic; +// returns +``` + +#### Float64Results.prototype.ci + +Confidence interval. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.ci; +// returns +``` + +#### Float64Results.prototype.nullValue + +Mean under the null hypothesis. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.nullValue; +// returns +``` + +#### Float64Results.prototype.sd + +Standard error of the mean. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.sd; +// returns +``` + +#### Float64Results.prototype.toString( \[options] ) + +Serializes a results object to a formatted string. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +Example output: + +```text + +Two-sample Z-test + +Alternative hypothesis: True mean is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + +Test Decision: Reject null in favor of alternative at 5% significance level + +``` + +#### Float64Results.prototype.toJSON( \[options] ) + +Serializes a results object as a JSON object. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a results instance. + +#### Float64Results.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a results object. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +``` + +#### stdlib_stats_ztest_two_sample_float64_results + +Structure for holding double-precision floating-point test results. + +```c +#include +#include + +struct stdlib_stats_ztest_two_sample_float64_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + double alpha; + + // p-value: + double pValue; + + // Test statistic: + double statistic; + + // Confidence interval: + double ci[ 2 ]; + + // Mean value under the null hypothesis: + double nullValue; + + // Standard error of the mean: + double sd; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js new file mode 100644 index 000000000000..328377e909f0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var Float64Results = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::constructor,new', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float64Results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var results; + var v; + var i; + + results = Float64Results; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt new file mode 100644 index 000000000000..dad9ed58e824 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns a two-sample Z-test double-precision floating-point results object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts new file mode 100644 index 000000000000..cac2812e3dbd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts @@ -0,0 +1,187 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: Float64Array; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue?: number; + + /** + * Standard error of the mean. + */ + sd?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array; + + /** + * Value of the mean under the null hypothesis + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a two-sample Z-test double-precision floating-point results object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns results object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float64Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ +declare var Results: ResultsConstructor; + + +// EXPORTS // + +export = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts new file mode 100644 index 000000000000..d770dcca67d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts @@ -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. +*/ + +import Results = require( './index' ); + + +// TESTS // + +// The function returns a results object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Results( {} ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js new file mode 100644 index 000000000000..838797f4e34a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Results = require( './../lib' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h new file mode 100644 index 000000000000..c6fcb293050b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h @@ -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. +*/ + +#ifndef STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H +#define STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H + +#include +#include + +/** +* Struct for storing test results. +*/ +struct stdlib_stats_ztest_two_sample_float64_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + double alpha; + + // p-value: + double pValue; + + // Test statistic: + double statistic; + + // Confidence interval: + double ci[ 2 ]; + + // Mean value under the null hypothesis: + double nullValue; + + // Standard error of the mean: + double sd; +}; + +#endif // !STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js new file mode 100644 index 000000000000..52c4ce16dd25 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Create a two-sample Z-test double-precision floating-point results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/float64 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float64Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js new file mode 100644 index 000000000000..ec7d760bf08b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var factory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + + +// MAIN // + +/** +* Returns a two-sample Z-test double-precision floating-point results object. +* +* @name Results +* @constructor +* @type {Function} +* @param {ArrayBuffer} [buffer] - underlying byte buffer +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Results} results object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float64Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ +var Results = factory( 'float64' ); + + +// EXPORTS // + +module.exports = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json new file mode 100644 index 000000000000..782c8f05e448 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/float64", + "version": "0.0.0", + "description": "Create a two-sample Z-test double-precision floating-point results object.", + "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", + "include": "./include", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js new file mode 100644 index 000000000000..468a79f74faf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js @@ -0,0 +1,408 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Results = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float64Results, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor for a fixed-width results object ', function test( t ) { + var expected; + var actual; + + actual = new Float64Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float64Results(); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float64Results( {} ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.3364; + actual.statistic = 11.7586; + actual.nullValue = 0.0; + actual.sd = 0.4563; + actual.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var results = new Float64Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var results; + var actual; + + results = new Float64Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var results = new Float64Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var results = new Float64Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + t.end(); +}); From bee73e4bd052ced9b8931e668d248e7d96c16ef2 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 12:47:47 +0000 Subject: [PATCH 4/6] feat: add `stats/base/ztest/two-sample/results/float32` --- .../two-sample/results/float32/README.md | 410 ++++++++++++++++++ .../results/float32/benchmark/benchmark.js | 70 +++ .../two-sample/results/float32/docs/repl.txt | 29 ++ .../results/float32/docs/types/index.d.ts | 187 ++++++++ .../results/float32/docs/types/test.ts | 39 ++ .../results/float32/examples/index.js | 38 ++ .../base/ztest/two-sample/results/float32.h | 54 +++ .../two-sample/results/float32/lib/index.js | 53 +++ .../two-sample/results/float32/lib/main.js | 62 +++ .../two-sample/results/float32/manifest.json | 36 ++ .../two-sample/results/float32/package.json | 67 +++ .../two-sample/results/float32/test/test.js | 409 +++++++++++++++++ 12 files changed, 1454 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md new file mode 100644 index 000000000000..f57811655217 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md @@ -0,0 +1,410 @@ + + +# Float32Results + +> Create a two-sample Z-test single-precision floating-point results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +``` + +#### Float32Results( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns a two-sample Z-test single-precision floating-point results object. + +```javascript +var results = new Float32Results(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **rejected**: boolean indicating whether the null hypothesis was rejected. +- **alternative**: the alternative hypothesis (e.g., `'two-sided'`, `'less'`, or `'greater'`). +- **alpha**: significance level. +- **pValue**: p-value. +- **statistic**: test statistic. +- **ci**: confidence interval as a [`Float32Array`][@stdlib/array/float32]. +- **nullValue**: mean under the null hypothesis. +- **sd**: standard error of the mean. + +#### Float32Results.prototype.rejected + +Boolean indicating whether the null hypothesis was rejected. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.rejected; +// returns +``` + +#### Float32Results.prototype.alternative + +The alternative hypothesis. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.alternative; +// returns +``` + +#### Float32Results.prototype.alpha + +Significance level. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.alpha; +// returns +``` + +#### Float32Results.prototype.pValue + +The test p-value. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.pValue; +// returns +``` + +#### Float32Results.prototype.statistic + +The test statistic. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.statistic; +// returns +``` + +#### Float32Results.prototype.ci + +Confidence interval. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.ci; +// returns +``` + +#### Float32Results.prototype.nullValue + +Mean under the null hypothesis. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.nullValue; +// returns +``` + +#### Float32Results.prototype.sd + +Standard error of the mean. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.sd; +// returns +``` + +#### Float32Results.prototype.toString( \[options] ) + +Serializes a results object to a formatted string. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +Example output: + +```text + +Two-sample Z-test + +Alternative hypothesis: True mean is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + +Test Decision: Reject null in favor of alternative at 5% significance level + +``` + +#### Float32Results.prototype.toJSON( \[options] ) + +Serializes a results object as a JSON object. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a results instance. + +#### Float32Results.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a results object. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +``` + +#### stdlib_stats_ztest_two_sample_float32_results + +Structure for holding single-precision floating-point test results. + +```c +#include +#include + +struct stdlib_stats_ztest_two_sample_float32_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + float alpha; + + // p-value: + float pValue; + + // Test statistic: + float statistic; + + // Confidence interval: + float ci[ 2 ]; + + // Mean value under the null hypothesis: + float nullValue; + + // Standard error of the mean: + float sd; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js new file mode 100644 index 000000000000..c9e290699a2c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var Float32Results = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::constructor,new', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float32Results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var results; + var v; + var i; + + results = Float32Results; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt new file mode 100644 index 000000000000..e30724623d96 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns a two-sample Z-test single-precision floating-point results object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts new file mode 100644 index 000000000000..44d39e9d78af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts @@ -0,0 +1,187 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: Float32Array; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue?: number; + + /** + * Standard error of the mean. + */ + sd?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float32Array; + + /** + * Value of the mean under the null hypothesis + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a two-sample Z-test single-precision floating-point results object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float32Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ +declare var Results: ResultsConstructor; + + +// EXPORTS // + +export = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts new file mode 100644 index 000000000000..d770dcca67d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts @@ -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. +*/ + +import Results = require( './index' ); + + +// TESTS // + +// The function returns a results object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Results( {} ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js new file mode 100644 index 000000000000..b545d0653637 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Results = require( './../lib' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h new file mode 100644 index 000000000000..7c31f592a646 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h @@ -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. +*/ + +#ifndef STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H +#define STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H + +#include +#include + +/** +* Struct for storing test results. +*/ +struct stdlib_stats_ztest_two_sample_float32_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + float alpha; + + // p-value: + float pValue; + + // Test statistic: + float statistic; + + // Confidence interval: + float ci[ 2 ]; + + // Mean value under the null hypothesis: + float nullValue; + + // Standard error of the mean: + float sd; +}; + +#endif // !STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js new file mode 100644 index 000000000000..c68bdcc04115 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Create a two-sample Z-test single-precision floating-point results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/float32 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float32Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js new file mode 100644 index 000000000000..80fd2a469fc4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var factory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + + +// MAIN // + +/** +* Returns a two-sample Z-test single-precision floating-point results object. +* +* @name Results +* @constructor +* @type {Function} +* @param {ArrayBuffer} [buffer] - underlying byte buffer +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Results} results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.3374; +* results.statistic = 0.9592; +* results.sd = 0.4535; +* results.ci = new Float32Array( [ -0.0316, 0.0923 ] ); +* results.rejected = false; +* +* var str = results.toString(); +* // returns +*/ +var Results = factory( 'float32' ); + + +// EXPORTS // + +module.exports = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json new file mode 100644 index 000000000000..dfbcaea97373 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/float32", + "version": "0.0.0", + "description": "Create a two-sample Z-test single-precision floating-point results object.", + "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", + "include": "./include", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js new file mode 100644 index 000000000000..a3cc1c42a996 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js @@ -0,0 +1,409 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Results = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float32Results, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor for a fixed-width results object ', function test( t ) { + var expected; + var actual; + + actual = new Float32Results({ + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float32Results(); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.3364 ); + actual.statistic = f32( 11.7586 ); + actual.nullValue = f32( 0.0 ); + actual.sd = f32( 0.4563 ); + actual.ci = new Float32Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float32Results( {} ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.3364 ); + actual.statistic = f32( 11.7586 ); + actual.nullValue = f32( 0.0 ); + actual.sd = f32( 0.4563 ); + actual.ci = new Float32Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.3364 ); + actual.statistic = f32( 11.7586 ); + actual.nullValue = f32( 0.0 ); + actual.sd = f32( 0.4563 ); + actual.ci = new Float32Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.3364 ); + actual.statistic = f32( 11.7586 ); + actual.nullValue = f32( 0.0 ); + actual.sd = f32( 0.4563 ); + actual.ci = new Float32Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.3364 ); + actual.statistic = f32( 11.7586 ); + actual.nullValue = f32( 0.0 ); + actual.sd = f32( 0.4563 ); + actual.ci = new Float32Array( [ 9.9983, 11.4123 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.3364 ), + 'statistic': f32( 11.7586 ), + 'nullValue': f32( 0.0 ), + 'sd': f32( 0.4563 ), + 'ci': new Float32Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.sd, expected.sd, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var results = new Float32Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var results; + var actual; + + results = new Float32Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var results = new Float32Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var results = new Float32Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + t.end(); +}); From 9aa0e024b09cc28a28ea64c69a61569d38cdfa78 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 12:48:14 +0000 Subject: [PATCH 5/6] feat: add `stats/base/ztest/two-sample/results/to-string` --- .../two-sample/results/to-string/README.md | 152 +++++++ .../results/to-string/benchmark/benchmark.js | 55 +++ .../results/to-string/docs/repl.txt | 42 ++ .../results/to-string/docs/types/index.d.ts | 136 ++++++ .../results/to-string/docs/types/test.ts | 130 ++++++ .../results/to-string/examples/index.js | 37 ++ .../two-sample/results/to-string/lib/index.js | 53 +++ .../two-sample/results/to-string/lib/main.js | 143 ++++++ .../two-sample/results/to-string/package.json | 64 +++ .../two-sample/results/to-string/test/test.js | 423 ++++++++++++++++++ 10 files changed, 1235 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md new file mode 100644 index 000000000000..a864dc8d571b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md @@ -0,0 +1,152 @@ + + +# res2str + +> Serialize a two-sample Z-test results object as a formatted string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +``` + +#### res2str( results\[, options] ) + +Serializes a two-sample Z-test results object as a formatted string. + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Float64Results(); + +// ... + +var s = res2str( results ); +// returns +``` + +The function supports the following parameters: + +- **results**: two-sample Z-test results object. +- **options**: function options. + +The function supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +
+ + + + + +
+ +## Notes + +- Example output: + + ```text + + Two-sample Z-test + + Alternative hypothesis: True mean is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + + Test Decision: Reject null in favor of alternative at 5% significance level + + ``` + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.3364; +results.statistic = 11.7586; +results.nullValue = 0.0; +results.sd = 0.4563; +results.ci = new Float64Array( [ 9.9983, 11.4123 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var s = res2str( results ); +console.log( s ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js new file mode 100644 index 000000000000..2ae07f20f27b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var res2str = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Results(), + new Float64Results() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = res2str( values[ i%values.length ] ); + if ( typeof v !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt new file mode 100644 index 000000000000..dff1573c285c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( results[, options] ) + Serializes a two-sample Z-test results object as a formatted string. + + Parameters + ---------- + results: Object + Two-sample Z-test results object. + + options: Object (optional) + Function options. + + options.digits: number (optional) + Number of digits to display after decimal points. Default: 4. + + options.decision: boolean (optional) + Boolean indicating whether to show the test decision. Default: true. + + Returns + ------- + out: string + Serialized results. + + Examples + -------- + > var res = { + ... 'rejected': false, + ... 'alpha': 0.05, + ... 'pValue': 0.3364, + ... 'statistic': 11.7586, + ... 'nullValue': 0.0, + ... 'sd': 0.4563, + ... 'ci': new {{alias:@stdlib/array/float64}}( [ 9.9983, 11.4123 ] ), + ... 'alternative': 'two-sided', + ... 'method': 'Two-sample Z-test' + ... }; + > var s = {{alias}}( res ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts new file mode 100644 index 000000000000..999755356afc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts @@ -0,0 +1,136 @@ +/* +* @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 + +/** +* Interface describing a results object. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: string; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array | Float32Array; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Number of digits to display after decimal points. Default: 4. + */ + digits?: number; + + /** + * Boolean indicating whether to show the test decision. + */ + decision?: boolean; +} + +/** +* Serializes a two-sample Z-test results object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Two-sample Z-test +* +* Alternative hypothesis: True mean is less than 1.0 +* +* pValue: 0.0406 +* statistic: 9.9901 +* 95% confidence interval: [9.7821, 10.4451] +* +* Test Decision: Reject null in favor of alternative at 5% significance level +* +* ``` +* +* @param results - two-sample Z-test results object +* @param options - options object +* @param options.digits - number of digits to display after decimal points +* @param options.decision - boolean indicating whether to show the test decision +* @returns serialized results +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = res2str( results ); +* // returns +*/ +declare function res2str( results: Results, options?: Options ): string; + + +// EXPORTS // + +export = res2str; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts new file mode 100644 index 000000000000..030d6f73b6ec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts @@ -0,0 +1,130 @@ +/* +* @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 res2str = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + const res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + res2str( res ); // $ExpectType string + res2str( res, {} ); // $ExpectType string +} + +// The compiler throws an error if provided first argument which is not a results object... +{ + res2str( '10' ); // $ExpectError + res2str( 10 ); // $ExpectError + res2str( true ); // $ExpectError + res2str( false ); // $ExpectError + res2str( null ); // $ExpectError + res2str( undefined ); // $ExpectError + res2str( [] ); // $ExpectError + res2str( {} ); // $ExpectError + res2str( ( x: number ): number => x ); // $ExpectError + + res2str( '10', {} ); // $ExpectError + res2str( 10, {} ); // $ExpectError + res2str( true, {} ); // $ExpectError + res2str( false, {} ); // $ExpectError + res2str( null, {} ); // $ExpectError + res2str( undefined, {} ); // $ExpectError + res2str( [], {} ); // $ExpectError + res2str( {}, {} ); // $ExpectError + res2str( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if provided a second argument which is not an object... +{ + const res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, '10' ); // $ExpectError + res2str( res, 10 ); // $ExpectError + res2str( res, true ); // $ExpectError + res2str( res, false ); // $ExpectError + res2str( res, null ); // $ExpectError + res2str( res, [] ); // $ExpectError + res2str( res, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if provided a `digits` option which is not a number... +{ + const res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, { 'digits': '10' } ); // $ExpectError + res2str( res, { 'digits': true } ); // $ExpectError + res2str( res, { 'digits': false } ); // $ExpectError + res2str( res, { 'digits': null } ); // $ExpectError + res2str( res, { 'digits': [] } ); // $ExpectError + res2str( res, { 'digits': {} } ); // $ExpectError + res2str( res, { 'digits': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if provided a `decision` option which is not a boolean... +{ + const res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, { 'decision': '10' } ); // $ExpectError + res2str( res, { 'decision': 10 } ); // $ExpectError + res2str( res, { 'decision': null } ); // $ExpectError + res2str( res, { 'decision': [] } ); // $ExpectError + res2str( res, { 'decision': {} } ); // $ExpectError + res2str( res, { 'decision': ( x: number ): number => x } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js new file mode 100644 index 000000000000..0ee5e3262b10 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( './../lib' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.3364; +results.statistic = 11.7586; +results.nullValue = 0.0; +results.sd = 0.4563; +results.ci = new Float64Array( [ 9.9983, 11.4123 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var s = res2str( results ); +console.log( s ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js new file mode 100644 index 000000000000..33c8c338f9fb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Serialize a two-sample Z-test results object as a formatted string. +* +* @module @stdlib/stats/base/ztest/two-sample/results/to-string +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = res2str( results ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js new file mode 100644 index 000000000000..0a6b5de7a9a9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js @@ -0,0 +1,143 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Serializes a two-sample Z-test results object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Two-sample Z-test +* +* Alternative hypothesis: True mean is less than 1.0 +* +* pValue: 0.0406 +* statistic: 9.9901 +* 95% confidence interval: [9.7821, 10.4451] +* +* Test Decision: Reject null in favor of alternative at 5% significance level +* +* ``` +* +* @param {Object} results - two-sample Z-test results object +* @param {Options} [opts] - options object +* @param {PositiveInteger} [opts.digits=4] - number of digits to display after decimal points +* @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {string} serialized results +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = toString( results ); +* // returns +*/ +function toString( results, opts ) { // eslint-disable-line stdlib/no-redeclare + var decision; + var level; + var dgts; + var out; + var alt; + var ci; + + dgts = 4; + decision = true; + if ( arguments.length > 1 ) { + if ( !isObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'digits' ) ) { + if ( !isPositiveInteger( opts.digits ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); + } + dgts = opts.digits; + } + if ( hasOwnProp( opts, 'decision' ) ) { + if ( !isBoolean( opts.decision ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) ); + } + decision = opts.decision; + } + } + switch ( results.alternative ) { + case 'less': + alt = 'less than'; + break; + case 'greater': + alt = 'greater than'; + break; + case 'two-sided': + default: + alt = 'not equal to'; + break; + } + + level = ( 1.0 - results.alpha ) * 100; + ci = results.ci; + + out = [ + '', + results.method, + '', + format( 'Alternative hypothesis: True mean is %s %0.'+dgts+'f', alt, results.nullValue ), + '', + format( ' pValue: %0.'+dgts+'f', results.pValue ), + format( ' statistic: %0.'+dgts+'f', results.statistic ), + format( ' %.'+dgts+'f%% confidence interval: [%0.'+dgts+'f, %0.'+dgts+'f]', level, ci[ 0 ], ci[ 1 ] ), + '' + ]; + if ( decision ) { + out.push( format( 'Test Decision: %s null in favor of alternative at %.'+dgts+'f%% significance level', ( results.rejected ) ? 'Reject' : 'Fail to reject', 100-level ) ); + out.push( '' ); + } + return out.join( '\n' ); +} + + +// EXPORTS // + +module.exports = toString; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json new file mode 100644 index 000000000000..42969fadb073 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/to-string", + "version": "0.0.0", + "description": "Serialize a two-sample Z-test results object as a formatted string.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "string" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js new file mode 100644 index 000000000000..d1b0a2bf3fba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js @@ -0,0 +1,423 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var Float64Array = require( '@stdlib/array/float64' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var res2str = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof res2str, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + res2str( results, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `digits` option which is not a positive integer', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + res2str( results, { + 'digits': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `digits` option which is not a boolean', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + -5, + NaN, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + res2str( results, { + 'decision': value + }); + }; + } +}); + +tape( 'the function serializes a results object to a string (rejected)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is not equal to 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (not rejected)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = false; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is not equal to 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Fail to reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (two-sided)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is not equal to 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (less)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'less' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is less than 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (greater)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'greater' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is greater than 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports displaying the test decision (decision=true)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value, { + 'decision': true + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is not equal to 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports not displaying the test decision (decision=false)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'less' ); + + actual = res2str( value, { + 'decision': false + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is less than 0.0000', + '', + ' pValue: 0.3364', + ' statistic: 11.7586', + ' 95.0000% confidence interval: [9.9983, 11.4123]', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the number of displayed digits (digits=2)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value, { + 'digits': 2 + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True mean is not equal to 0.00', + '', + ' pValue: 0.34', + ' statistic: 11.76', + ' 95.00% confidence interval: [10.00, 11.41]', + '', + 'Test Decision: Reject null in favor of alternative at 5.00% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From b0c3f166ab4f77635d6f8ecbce6f951cd43a447c Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 20 Jun 2025 12:48:53 +0000 Subject: [PATCH 6/6] feat: add `stats/base/ztest/two-sample/results/to-json` --- 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 --- --- .../two-sample/results/to-json/README.md | 128 ++++++++++++++++++ .../results/to-json/benchmark/benchmark.js | 55 ++++++++ .../two-sample/results/to-json/docs/repl.txt | 33 +++++ .../results/to-json/docs/types/index.d.ts | 100 ++++++++++++++ .../results/to-json/docs/types/test.ts | 50 +++++++ .../results/to-json/examples/index.js | 37 +++++ .../two-sample/results/to-json/lib/index.js | 53 ++++++++ .../two-sample/results/to-json/lib/main.js | 69 ++++++++++ .../two-sample/results/to-json/package.json | 64 +++++++++ .../two-sample/results/to-json/test/test.js | 71 ++++++++++ 10 files changed, 660 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md new file mode 100644 index 000000000000..0acf8d44908d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md @@ -0,0 +1,128 @@ + + +# res2json + +> Serialize a two-sample Z-test results object as a JSON object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +``` + +#### res2json( results ) + +Serializes a two-sample Z-test results object as a JSON object. + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Float64Results(); + +// ... + +var o = res2json( results ); +// returns {...} +``` + +The function supports the following parameters: + +- **results**: two-sample Z-test results object. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.3364; +results.statistic = 11.7586; +results.nullValue = 0.0; +results.sd = 0.4563; +results.ci = new Float64Array( [ 9.9983, 11.4123 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var o = res2json( results ); +console.log( o ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js new file mode 100644 index 000000000000..ea0c5fe26db8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var pkg = require( './../package.json' ).name; +var res2json = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Results(), + new Float64Results() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = res2json( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isPlainObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt new file mode 100644 index 000000000000..47156bc1c834 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( results ) + Serializes a two-sample Z-test results object as a JSON object. + + Parameters + ---------- + results: Object + Two-sample Z-test results object. + + Returns + ------- + out: Object + Serialized object. + + Examples + -------- + > var res = { + ... 'rejected': false, + ... 'alpha': 0.05, + ... 'pValue': 0.3364, + ... 'statistic': 11.7586, + ... 'nullValue': 0.0, + ... 'sd': 0.4563, + ... 'ci': new {{alias:@stdlib/array/float64}}( [ 9.9983, 11.4123 ] ), + ... 'alternative': 'two-sided', + ... 'method': 'Two-sample Z-test' + ... }; + > var o = {{alias}}( res ) + {...} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts new file mode 100644 index 000000000000..f8ac96bbf3ac --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts @@ -0,0 +1,100 @@ +/* +* @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 + +/** +* Interface describing a results object. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: string; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array | Float32Array; + + /** + * Value of the mean under the null hypothesis. + */ + nullValue: number; + + /** + * Standard error of the mean. + */ + sd: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Serializes a two-sample Z-test results object as a JSON object. +* +* @param results - two-sample Z-test results object +* @returns serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = toJSON( results ); +* // returns {...} +*/ +declare function res2json( results: Results ): Results; + + +// EXPORTS // + +export = res2json; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts new file mode 100644 index 000000000000..ce3615f9b6b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts @@ -0,0 +1,50 @@ +/* +* @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 res2json = require( './index' ); + + +// TESTS // + +// The function returns an object... +{ + const res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + res2json( res ); // $ExpectType Results +} + +// The compiler throws an error if not provided a results object... +{ + res2json( 10 ); // $ExpectError + res2json( true ); // $ExpectError + res2json( false ); // $ExpectError + res2json( null ); // $ExpectError + res2json( undefined ); // $ExpectError + res2json( [] ); // $ExpectError + res2json( {} ); // $ExpectError + res2json( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js new file mode 100644 index 000000000000..0fcefcfc869d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2json = require( './../lib' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.3364; +results.statistic = 11.7586; +results.nullValue = 0.0; +results.sd = 0.4563; +results.ci = new Float64Array( [ 9.9983, 11.4123 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var o = res2json( results ); +console.log( o ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js new file mode 100644 index 000000000000..3f1434ee3060 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Serialize a two-sample Z-test results object as a JSON object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/to-json +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = res2json( results ); +* // returns {...} +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js new file mode 100644 index 000000000000..dd21d894804d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.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 typedarray2json = require( '@stdlib/array/to-json' ); + + +// MAIN // + +/** +* Serializes a two-sample Z-test results object as a JSON object. +* +* @param {Object} results - two-sample Z-test results object +* @returns {Object} serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': false, +* 'alpha': 0.05, +* 'pValue': 0.3364, +* 'statistic': 11.7586, +* 'nullValue': 0.0, +* 'sd': 0.4563, +* 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = toJSON( results ); +* // returns {...} +*/ +function toJSON( results ) { + return { + 'rejected': results.rejected, + 'alpha': results.alpha, + 'pValue': results.pValue, + 'statistic': results.statistic, + 'nullValue': results.nullValue, + 'sd': results.sd, + 'ci': typedarray2json( results.ci ), + 'alternative': results.alternative, + 'method': results.method + }; +} + + +// EXPORTS // + +module.exports = toJSON; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json new file mode 100644 index 000000000000..ca80c296b45a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/to-json", + "version": "0.0.0", + "description": "Serialize a two-sample Z-test results object as a JSON object.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "json" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js new file mode 100644 index 000000000000..a2334b7f0350 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js @@ -0,0 +1,71 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var res2json = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof res2json, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function serializes a results object to JSON', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.3364; + value.statistic = 11.7586; + value.nullValue = 0.0; + value.sd = 0.4563; + value.ci = new Float64Array( [ 9.9983, 11.4123 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.3364, + 'statistic': 11.7586, + 'nullValue': 0.0, + 'sd': 0.4563, + 'ci': { + 'type': 'Float64Array', + 'data': [ 9.9983, 11.4123 ] + }, + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + actual = res2json( value ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +});