Skip to content

Commit b01aeba

Browse files
gururaj1512kgrytestdlib-bot
authored
feat: add stats/base/ztest/two-sample/results
PR-URL: #7448 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <noreply@stdlib.io>
1 parent 4b3f6b6 commit b01aeba

File tree

55 files changed

+6944
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6944
-2
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# resultsFactory
22+
23+
> Create a new constructor for creating a two-sample Z-test results object.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' );
41+
```
42+
43+
#### resultsFactory( dtype )
44+
45+
Returns a new constructor for creating a two-sample Z-test results object.
46+
47+
```javascript
48+
var Results = resultsFactory( 'float64' );
49+
// returns <Function>
50+
51+
var r = new Results();
52+
// returns <Results>
53+
```
54+
55+
The function supports the following parameters:
56+
57+
- **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`.
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
64+
65+
<section class="notes">
66+
67+
## Notes
68+
69+
- 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.
70+
71+
</section>
72+
73+
<!-- /.notes -->
74+
75+
<!-- Package usage examples. -->
76+
77+
<section class="examples">
78+
79+
## Examples
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var Float64Array = require( '@stdlib/array/float64' );
85+
var Float32Array = require( '@stdlib/array/float32' );
86+
var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' );
87+
88+
var Results = resultsFactory( 'float64' );
89+
var results = new Results({
90+
'rejected': true,
91+
'alpha': 0.05,
92+
'pValue': 0.0132,
93+
'statistic': 2.4773,
94+
'nullValue': 0.0,
95+
'xmean': 3.7561,
96+
'ymean': 3.0129,
97+
'ci': new Float64Array( [ 0.1552, 1.3311 ] ),
98+
'alternative': 'two-sided'
99+
});
100+
101+
var str = results.toString({
102+
'format': 'linear'
103+
});
104+
console.log( str );
105+
106+
Results = resultsFactory( 'float32' );
107+
results = new Results({
108+
'rejected': true,
109+
'alpha': 0.05,
110+
'pValue': 0.0132,
111+
'statistic': 2.4773,
112+
'nullValue': 0.0,
113+
'xmean': 3.7561,
114+
'ymean': 3.0129,
115+
'ci': new Float32Array( [ 0.1552, 1.3311 ] ),
116+
'alternative': 'two-sided'
117+
});
118+
119+
str = results.toString({
120+
'format': 'linear'
121+
});
122+
console.log( str );
123+
```
124+
125+
</section>
126+
127+
<!-- /.examples -->
128+
129+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
130+
131+
<section class="references">
132+
133+
</section>
134+
135+
<!-- /.references -->
136+
137+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
138+
139+
<section class="related">
140+
141+
</section>
142+
143+
<!-- /.related -->
144+
145+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
146+
147+
<section class="links">
148+
149+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct
150+
151+
</section>
152+
153+
<!-- /.links -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isFunction = require( '@stdlib/assert/is-function' );
25+
var isObject = require( '@stdlib/assert/is-object' );
26+
var pkg = require( './../package.json' ).name;
27+
var factory = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var v;
35+
var i;
36+
37+
values = [
38+
'float64',
39+
'float32'
40+
];
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
v = factory( values[ i%values.length ] );
45+
if ( typeof v !== 'function' ) {
46+
b.fail( 'should return a function' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isFunction( v ) ) {
51+
b.fail( 'should return a function' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
56+
57+
bench( pkg+'::constructor,new', function benchmark( b ) {
58+
var values;
59+
var v;
60+
var i;
61+
62+
values = [
63+
factory( 'float64' ),
64+
factory( 'float32' )
65+
];
66+
67+
b.tic();
68+
for ( i = 0; i < b.iterations; i++ ) {
69+
v = new ( values[ i%values.length ] )();
70+
if ( typeof v !== 'object' ) {
71+
b.fail( 'should return an object' );
72+
}
73+
}
74+
b.toc();
75+
if ( !isObject( v ) ) {
76+
b.fail( 'should return an object' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
});
81+
82+
bench( pkg+'::constructor,no_new', function benchmark( b ) {
83+
var values;
84+
var v;
85+
var i;
86+
87+
values = [
88+
factory( 'float64' ),
89+
factory( 'float32' )
90+
];
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
v = values[ i%values.length ]();
95+
if ( typeof v !== 'object' ) {
96+
b.fail( 'should return an object' );
97+
}
98+
}
99+
b.toc();
100+
if ( !isObject( v ) ) {
101+
b.fail( 'should return an object' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
{{alias}}( dtype )
3+
Returns a constructor for creating a two-sample Z-test results object.
4+
5+
Parameters
6+
----------
7+
dtype: string
8+
Floating-point data type for storing floating-point results.
9+
10+
Returns
11+
-------
12+
fcn: Function
13+
Constructor.
14+
15+
Examples
16+
--------
17+
> var R = {{alias}}( 'float64' );
18+
> var r = new R();
19+
> r.toString( { 'format': 'linear' } )
20+
<string>
21+
22+
See Also
23+
--------
24+

0 commit comments

Comments
 (0)