diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/README.md new file mode 100644 index 000000000000..3d408ccb50f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/README.md @@ -0,0 +1,186 @@ + + +# dztest2 + +> Compute a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays. + +
+ +A Z-test commonly refers to a two-sample location test which compares the means of two independent sets of measurements `X` and `Y` when the population standard deviations are known. A Z-test supports testing three different null hypotheses `H0`: + +- `H0: μX - μY ≥ Δ` versus the alternative hypothesis `H1: μX - μY < Δ`. +- `H0: μX - μY ≤ Δ` versus the alternative hypothesis `H1: μX - μY > Δ`. +- `H0: μX - μY = Δ` versus the alternative hypothesis `H1: μX - μY ≠ Δ`. + +Here, `μX` and `μY` are the true population means of samples `X` and `Y`, respectively, and `Δ` is the hypothesized difference in means (typically `0` by default). + +
+ + + +
+ +## Usage + +```javascript +var dztest2 = require( '@stdlib/stats/base/ndarray/dztest2' ); +``` + +#### dztest2( arrays ) + +Computes a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays. + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/array/struct-factory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var opts = { + 'dtype': 'float64' +}; + +var xbuf = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var x = new ndarray( opts.dtype, xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + +var ybuf = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +var y = new ndarray( opts.dtype, ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); + +var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 0.05, opts ); +var diff = scalar2ndarray( 0.0, opts ); +var sigmax = scalar2ndarray( 1.0, opts ); +var sigmay = scalar2ndarray( 2.0, opts ); + +var ResultsArray = structFactory( Float64Results ); +var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); + +var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + +var bool = ( v === out ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays in order: + + 1. first one-dimensional input ndarray. + 2. second one-dimensional input ndarray. + 3. a zero-dimensional output ndarray containing a [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. + 4. a zero-dimensional ndarray specifying the alternative hypothesis. + 5. a zero-dimensional ndarray specifying the significance level. + 6. a zero-dimensional ndarray specifying the difference in means under the null hypothesis. + 7. a zero-dimensional ndarray specifying the known standard deviation of the first one-dimensional input ndarray. + 8. a zero-dimensional ndarray specifying the known standard deviation of the second one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- As a general rule of thumb, a Z-test is most reliable for sample sizes greater than `50`. For smaller sample sizes or when the standard deviation is unknown, prefer a t-test. + +
+ + + +
+ +## Examples + + + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/array/struct-factory' ); +var normal = require( '@stdlib/random/array/normal' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dztest2 = require( '@stdlib/stats/base/ndarray/dztest2' ); + +var opts = { + 'dtype': 'float64' +}; + +// Create one-dimensional ndarrays containing pseudorandom numbers drawn from a normal distribution: +var xbuf = normal( 100, 0.0, 1.0, opts ); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var ybuf = normal( 100, 0.0, 1.0, opts ); +var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +// Specify the alternative hypothesis: +var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' +}); + +// Specify the significance level: +var alpha = scalar2ndarray( 0.05, opts ); + +// Specify the difference in means under the null hypothesis: +var diff = scalar2ndarray( 0.0, opts ); + +// Specify the known standard deviations: +var sigmax = scalar2ndarray( 1.0, opts ); +var sigmay = scalar2ndarray( 1.0, opts ); + +// Create a zero-dimensional results ndarray: +var ResultsArray = structFactory( Float64Results ); +var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); + +// Perform a Z-test: +var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); +console.log( v.get().toString() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/benchmark/benchmark.js new file mode 100644 index 000000000000..2d92d940232f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/benchmark/benchmark.js @@ -0,0 +1,128 @@ +/** +* @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 normal = require( '@stdlib/random/array/normal' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/array/struct-factory' ); +var pkg = require( './../package.json' ).name; +var dztest2 = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; +var ResultsArray = structFactory( Float64Results ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var xbuf; + var ybuf; + var obuf; + var out; + var alt; + var x; + var y; + + xbuf = normal( len, 0.0, 1.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + ybuf = normal( len, 0.0, 1.0, options ); + y = new ndarray( options.dtype, ybuf, [ len ], [ 1 ], 0, 'row-major' ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + alt = scalar2ndarray( resolveEnum( 'two-sided' ), 'int8', 'row-major' ); + alpha = scalar2ndarray( 0.05, options.dtype, 'row-major' ); + diff = scalar2ndarray( 0.0, options.dtype, 'row-major' ); + sigmax = scalar2ndarray( 1.0, options.dtype, 'row-major' ); + sigmay = scalar2ndarray( 1.0, options.dtype, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( v.get().statistic ) || isnan( v.get().pValue ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/repl.txt new file mode 100644 index 000000000000..801ebc77d783 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/repl.txt @@ -0,0 +1,69 @@ + +{{alias}}( arrays ) + Computes a two-sample Z-test for two one-dimensional double-precision + floating-point ndarrays. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays in order: + + - first one-dimensional input ndarray. + - second one-dimensional input ndarray. + - a zero-dimensional output ndarray containing a results object. + - a zero-dimensional ndarray specifying the alternative hypothesis. + - a zero-dimensional ndarray specifying the significance level. + - a zero-dimensional ndarray specifying the difference in means under + the null hypothesis. + - a zero-dimensional ndarray specifying the known standard deviation of + the first one-dimensional input ndarray. + - a zero-dimensional ndarray specifying the known standard deviation of + the second one-dimensional input ndarray. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + // Create input ndarrays: + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); + > var ybuf = new {{alias:@stdlib/array/float64}}( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + > var dt = 'float64'; + > var sh = [ xbuf.length ]; + > var st = [ 1 ]; + > var oo = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); + > var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, st, oo, ord ); + + // Create the output ndarray: + > var S = {{alias:@stdlib/stats/base/ztest/two-sample/results/float64}}; + > var Results = {{alias:@stdlib/array/struct-factory}}( S ); + > var obuf = new Results( 1 ); + > var out = new {{alias:@stdlib/ndarray/ctor}}( S, obuf, [], [ 0 ], 0, ord ); + + // Specify the alternative hypothesis: + > var alt = {{alias:@stdlib/ndarray/from-scalar}}( 'two-sided' ); + + // Specify the significance level: + > var opts = { 'dtype': dt }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 0.05, opts ); + + // Specify the difference in means under the null hypothesis: + > var diff = {{alias:@stdlib/ndarray/from-scalar}}( 0.0, opts ); + + // Specify the known standard deviations: + > var sigmax = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + > var sigmay = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, opts ); + + // Perform a Z-test: + > {{alias}}( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + + // Print the results: + > out.get().toString() + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/index.d.ts new file mode 100644 index 000000000000..90fb8c60dfb5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/index.d.ts @@ -0,0 +1,93 @@ +/* +* @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 + +/// + +import { float64ndarray, ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays in order: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a zero-dimensional output ndarray containing a results object. +* - a zero-dimensional ndarray specifying the alternative hypothesis. +* - a zero-dimensional ndarray specifying the significance level. +* - a zero-dimensional ndarray specifying the difference in means under the null hypothesis. +* - a zero-dimensional ndarray specifying the known standard deviation of the first one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying the known standard deviation of the second one-dimensional input ndarray. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +* var structFactory = require( '@stdlib/array/struct-factory' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* // Define one-dimensional input ndarrays: +* var xbuf = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* // Specify the alternative hypothesis: +* var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { +* 'dtype': 'int8' +* }); +* +* // Specify the significance level: +* var alpha = scalar2ndarray( 0.05, opts ); +* +* // Specify the difference in means under the null hypothesis: +* var diff = scalar2ndarray( 0.0, opts ); +* +* // Specify the known standard deviations: +* var sigmax = scalar2ndarray( 1.0, opts ); +* var sigmay = scalar2ndarray( 2.0, opts ); +* +* // Create a zero-dimensional results ndarray: +* var ResultsArray = structFactory( Float64Results ); +* var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); +* +* // Perform a Z-test: +* var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); +* // returns +* +* console.log( v.get().toString() ); +*/ +declare function dztest2( arrays: [ float64ndarray, float64ndarray, T, float64ndarray, float64ndarray, float64ndarray, float64ndarray, float64ndarray ] ): T; + + +// EXPORTS // + +export = dztest2; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/test.ts new file mode 100644 index 000000000000..6eba30b6b10e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/docs/types/test.ts @@ -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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import dztest2 = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + dztest2( [ x, x, x, x, x, x, x, x ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dztest2( '10' ); // $ExpectError + dztest2( 10 ); // $ExpectError + dztest2( true ); // $ExpectError + dztest2( false ); // $ExpectError + dztest2( null ); // $ExpectError + dztest2( undefined ); // $ExpectError + dztest2( [] ); // $ExpectError + dztest2( {} ); // $ExpectError + dztest2( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + dztest2(); // $ExpectError + dztest2( [ x, x, x, x, x, x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/examples/index.js new file mode 100644 index 000000000000..fc77ff17d175 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/examples/index.js @@ -0,0 +1,64 @@ +/** +* @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 structFactory = require( '@stdlib/array/struct-factory' ); +var normal = require( '@stdlib/random/array/normal' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dztest2 = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +// Create one-dimensional ndarrays containing pseudorandom numbers drawn from a normal distribution: +var xbuf = normal( 100, 0.0, 1.0, opts ); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var ybuf = normal( 100, 0.0, 1.0, opts ); +var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +// Specify the alternative hypothesis: +var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' +}); + +// Specify the significance level: +var alpha = scalar2ndarray( 0.05, opts ); + +// Specify the difference in means under the null hypothesis: +var diff = scalar2ndarray( 0.0, opts ); + +// Specify the known standard deviations: +var sigmax = scalar2ndarray( 1.0, opts ); +var sigmay = scalar2ndarray( 1.0, opts ); + +// Create a zero-dimensional results ndarray: +var ResultsArray = structFactory( Float64Results ); +var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); + +// Perform a Z-test: +var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); +console.log( v.get().toString() ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/index.js new file mode 100644 index 000000000000..4179b4dde936 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/index.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays. +* +* @module @stdlib/stats/base/ndarray/dztest2 +* +* @example +* var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +* var structFactory = require( '@stdlib/array/struct-factory' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var dztest2 = require( '@stdlib/stats/base/ndarray/dztest2' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* // Define one-dimensional input ndarrays: +* var xbuf = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* // Specify the alternative hypothesis: +* var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { +* 'dtype': 'int8' +* }); +* +* // Specify the significance level: +* var alpha = scalar2ndarray( 0.05, opts ); +* +* // Specify the difference in means under the null hypothesis: +* var diff = scalar2ndarray( 0.0, opts ); +* +* // Specify the known standard deviations: +* var sigmax = scalar2ndarray( 1.0, opts ); +* var sigmay = scalar2ndarray( 2.0, opts ); +* +* // Create a zero-dimensional results ndarray: +* var ResultsArray = structFactory( Float64Results ); +* var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); +* +* // Perform a Z-test: +* var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); +* // returns +* +* console.log( v.get().toString() ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/main.js new file mode 100644 index 000000000000..63f9ea68e489 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/lib/main.js @@ -0,0 +1,124 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/stats/strided/dztest2' ).ndarray; + + +// MAIN // + +/** +* Computes a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays in order: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a zero-dimensional output ndarray containing a results object. +* - a zero-dimensional ndarray specifying the alternative hypothesis. +* - a zero-dimensional ndarray specifying the significance level. +* - a zero-dimensional ndarray specifying the difference in means under the null hypothesis. +* - a zero-dimensional ndarray specifying the known standard deviation of the first one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying the known standard deviation of the second one-dimensional input ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarrayLike} output ndarray +* +* @example +* var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +* var structFactory = require( '@stdlib/array/struct-factory' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* // Define one-dimensional input ndarrays: +* var xbuf = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* // Specify the alternative hypothesis: +* var alt = scalar2ndarray( resolveEnum( 'two-sided' ), { +* 'dtype': 'int8' +* }); +* +* // Specify the significance level: +* var alpha = scalar2ndarray( 0.05, opts ); +* +* // Specify the difference in means under the null hypothesis: +* var diff = scalar2ndarray( 0.0, opts ); +* +* // Specify the known standard deviations: +* var sigmax = scalar2ndarray( 1.0, opts ); +* var sigmay = scalar2ndarray( 2.0, opts ); +* +* // Create a zero-dimensional results ndarray: +* var ResultsArray = structFactory( Float64Results ); +* var out = new ndarray( Float64Results, new ResultsArray( 1 ), [], [ 0 ], 0, 'row-major' ); +* +* // Perform a Z-test: +* var v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); +* // returns +* +* console.log( v.get().toString() ); +*/ +function dztest2( arrays ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var alt; + var out; + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + out = ndarraylike2scalar( arrays[ 2 ] ); + + alt = ndarraylike2scalar( arrays[ 3 ] ); + alpha = ndarraylike2scalar( arrays[ 4 ] ); + diff = ndarraylike2scalar( arrays[ 5 ] ); + sigmax = ndarraylike2scalar( arrays[ 6 ] ); + sigmay = ndarraylike2scalar( arrays[ 7 ] ); + + strided( numelDimension( x, 0 ), numelDimension( y, 0 ), alt, alpha, diff, sigmax, getData( x ), getStride( x, 0 ), getOffset( x ), sigmay, getData( y ), getStride( y, 0 ), getOffset( y ), out ); // eslint-disable-line max-len + + return arrays[ 2 ]; +} + + +// EXPORTS // + +module.exports = dztest2; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/package.json new file mode 100644 index 000000000000..b866910dc128 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/base/ndarray/dztest2", + "version": "0.0.0", + "description": "Compute a two-sample Z-test for two one-dimensional double-precision floating-point ndarrays.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "z-test", + "ztest", + "hypothesis", + "normality", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/test/test.js new file mode 100644 index 000000000000..672648e9de4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dztest2/test/test.js @@ -0,0 +1,352 @@ +/** +* @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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/array/struct-factory' ); +var normal = require( '@stdlib/random/strided/normal' ).ndarray; +var zeros = require( '@stdlib/array/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var dztest2 = require( './../lib' ); + + +// VARIABLES // + +var ResultsArray = structFactory( Float64Results ); +var RANDOM_OPTS = { + 'seed': 12345 +}; + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dztest2.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function performs a Z-test over two one-dimensional ndarrays (two-sided)', function test( t ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var opts; + var xbuf; + var ybuf; + var obuf; + var alt; + var out; + var x; + var y; + var v; + + opts = { + 'dtype': 'float64' + }; + + alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' + }); + alpha = scalar2ndarray( 0.1, opts ); + sigmax = scalar2ndarray( 1.0, opts ); + sigmay = scalar2ndarray( 1.0, opts ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + // Generate large enough arrays to effectively guarantee results... + xbuf = zeros( 10000, opts.dtype ); + ybuf = zeros( 10000, opts.dtype ); + + normal( xbuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + x = vector( xbuf, xbuf.length, 1, 0 ); + + normal( ybuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + y = vector( ybuf, ybuf.length, 1, 0 ); + + diff = scalar2ndarray( 0.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, false, 'returns expected value' ); + + diff = scalar2ndarray( 10.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + normal( xbuf.length, [ 4.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + normal( ybuf.length, [ 2.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + + diff = scalar2ndarray( 1.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a Z-test over two one-dimensional ndarrays (less)', function test( t ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var opts; + var xbuf; + var ybuf; + var obuf; + var alt; + var out; + var x; + var y; + var v; + + opts = { + 'dtype': 'float64' + }; + + alt = scalar2ndarray( resolveEnum( 'less' ), { + 'dtype': 'int8' + }); + alpha = scalar2ndarray( 0.1, opts ); + sigmax = scalar2ndarray( 1.0, opts ); + sigmay = scalar2ndarray( 1.0, opts ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + // Generate large enough arrays to effectively guarantee results... + xbuf = zeros( 10000, opts.dtype ); + ybuf = zeros( 10000, opts.dtype ); + + normal( xbuf.length, [ 2.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + x = vector( xbuf, xbuf.length, 1, 0 ); + + normal( ybuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + y = vector( ybuf, ybuf.length, 1, 0 ); + + diff = scalar2ndarray( 0.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, false, 'returns expected value' ); + + normal( xbuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + normal( ybuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + + diff = scalar2ndarray( 1.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a Z-test over two one-dimensional ndarrays (greater)', function test( t ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var opts; + var xbuf; + var ybuf; + var obuf; + var alt; + var out; + var x; + var y; + var v; + + opts = { + 'dtype': 'float64' + }; + + alt = scalar2ndarray( resolveEnum( 'greater' ), { + 'dtype': 'int8' + }); + alpha = scalar2ndarray( 0.1, opts ); + sigmax = scalar2ndarray( 1.0, opts ); + sigmay = scalar2ndarray( 1.0, opts ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + // Generate large enough arrays to effectively guarantee results... + xbuf = zeros( 10000, opts.dtype ); + ybuf = zeros( 10000, opts.dtype ); + + normal( xbuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + x = vector( xbuf, xbuf.length, 1, 0 ); + + normal( ybuf.length, [ 2.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + y = vector( ybuf, ybuf.length, 1, 0 ); + + diff = scalar2ndarray( 0.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, false, 'returns expected value' ); + + normal( xbuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 0, RANDOM_OPTS ); + normal( ybuf.length, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 0, RANDOM_OPTS ); + + diff = scalar2ndarray( -1.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var opts; + var xbuf; + var ybuf; + var obuf; + var alt; + var out; + var x; + var y; + var v; + + opts = { + 'dtype': 'float64' + }; + + alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' + }); + alpha = scalar2ndarray( 0.1, opts ); + sigmax = scalar2ndarray( 1.0, opts ); + sigmay = scalar2ndarray( 1.0, opts ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + // Generate large enough arrays to effectively guarantee results... + xbuf = zeros( 10000, opts.dtype ); + ybuf = zeros( 10000, opts.dtype ); + + normal( 5000, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 2, 0, RANDOM_OPTS ); + x = vector( xbuf, 5000, 2, 0 ); + + normal( 5000, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 2, 0, RANDOM_OPTS ); + y = vector( ybuf, 5000, 2, 0 ); + + diff = scalar2ndarray( 0.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, false, 'returns expected value' ); + + normal( 5000, [ 4.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 2, 0, RANDOM_OPTS ); + normal( 5000, [ 2.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 2, 0, RANDOM_OPTS ); + + diff = scalar2ndarray( 10.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var sigmax; + var sigmay; + var alpha; + var diff; + var opts; + var xbuf; + var ybuf; + var obuf; + var alt; + var out; + var x; + var y; + var v; + + opts = { + 'dtype': 'float64' + }; + + alt = scalar2ndarray( resolveEnum( 'two-sided' ), { + 'dtype': 'int8' + }); + alpha = scalar2ndarray( 0.1, opts ); + sigmax = scalar2ndarray( 1.0, opts ); + sigmay = scalar2ndarray( 1.0, opts ); + + obuf = new ResultsArray( 1 ); + out = new ndarray( Float64Results, obuf, [], [ 0 ], 0, 'row-major' ); + + // Generate large enough arrays to effectively guarantee results... + xbuf = zeros( 10000, opts.dtype ); + ybuf = zeros( 10000, opts.dtype ); + + normal( 5000, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 5000, RANDOM_OPTS ); + x = vector( xbuf, 5000, 1, 5000 ); + + normal( 5000, [ 0.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 5000, RANDOM_OPTS ); + y = vector( ybuf, 5000, 1, 5000 ); + + diff = scalar2ndarray( 0.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, false, 'returns expected value' ); + + normal( 5000, [ 100.0 ], 0, 0, [ 1.0 ], 0, 0, xbuf, 1, 5000, RANDOM_OPTS ); + normal( 5000, [ 100.0 ], 0, 0, [ 1.0 ], 0, 0, ybuf, 1, 5000, RANDOM_OPTS ); + + diff = scalar2ndarray( 1.0, opts ); + v = dztest2( [ x, y, out, alt, alpha, diff, sigmax, sigmay ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( out.get().rejected, true, 'returns expected value' ); + + t.end(); +});