Skip to content

Commit 571f10d

Browse files
committed
feat: add stats/base/ztest/one-sample/results/float32
--- 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 ---
1 parent 0b5a64c commit 571f10d

File tree

10 files changed

+1273
-0
lines changed

10 files changed

+1273
-0
lines changed
Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
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+
# Float32Results
22+
23+
> Create a one-sample Z-test single-precision floating-point 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 Float32Results = require( '@stdlib/stats/base/ztest/one-sample/results/float32' );
41+
```
42+
43+
#### Float32Results( \[arg\[, byteOffset\[, byteLength]]] )
44+
45+
Returns a one-sample Z-test single-precision floating-point results object.
46+
47+
```javascript
48+
var results = new Float32Results();
49+
// returns {...}
50+
```
51+
52+
The function supports the following parameters:
53+
54+
- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_).
55+
- **byteOffset**: byte offset (_optional_).
56+
- **byteLength**: maximum byte length (_optional_).
57+
58+
A data object argument is an object having one or more of the following properties:
59+
60+
- **rejected**: boolean indicating whether the null hypothesis was rejected.
61+
- **alternative**: the alternative hypothesis (e.g., `'two-sided'`, `'less'`, or `'greater'`).
62+
- **alpha**: significance level.
63+
- **pValue**: p-value.
64+
- **statistic**: test statistic.
65+
- **ci**: confidence interval as a [`Float32Array`][@stdlib/array/float32].
66+
- **nullValue**: mean under the null hypothesis.
67+
- **sd**: standard error of the mean.
68+
69+
#### Float32Results.prototype.rejected
70+
71+
Boolean indicating whether the null hypothesis was rejected.
72+
73+
```javascript
74+
var results = new Float32Results();
75+
// returns {...}
76+
77+
// ...
78+
79+
var v = results.rejected;
80+
// returns <boolean>
81+
```
82+
83+
#### Float32Results.prototype.alternative
84+
85+
The alternative hypothesis.
86+
87+
```javascript
88+
var results = new Float32Results();
89+
// returns {...}
90+
91+
// ...
92+
93+
var v = results.alternative;
94+
// returns <string>
95+
```
96+
97+
#### Float32Results.prototype.alpha
98+
99+
Significance level.
100+
101+
```javascript
102+
var results = new Float32Results();
103+
// returns {...}
104+
105+
// ...
106+
107+
var v = results.alpha;
108+
// returns <number>
109+
```
110+
111+
#### Float32Results.prototype.pValue
112+
113+
The test p-value.
114+
115+
```javascript
116+
var results = new Float32Results();
117+
// returns {...}
118+
119+
// ...
120+
121+
var v = results.pValue;
122+
// returns <number>
123+
```
124+
125+
#### Float32Results.prototype.statistic
126+
127+
The test statistic.
128+
129+
```javascript
130+
var results = new Float32Results();
131+
// returns {...}
132+
133+
// ...
134+
135+
var v = results.statistic;
136+
// returns <number>
137+
```
138+
139+
#### Float32Results.prototype.ci
140+
141+
Confidence interval.
142+
143+
```javascript
144+
var results = new Float32Results();
145+
// returns {...}
146+
147+
// ...
148+
149+
var v = results.ci;
150+
// returns <Float32Array>
151+
```
152+
153+
#### Float32Results.prototype.nullValue
154+
155+
Mean under the null hypothesis.
156+
157+
```javascript
158+
var results = new Float32Results();
159+
// returns {...}
160+
161+
// ...
162+
163+
var v = results.nullValue;
164+
// returns <number>
165+
```
166+
167+
#### Float32Results.prototype.sd
168+
169+
Standard error of the mean.
170+
171+
```javascript
172+
var results = new Float32Results();
173+
// returns {...}
174+
175+
// ...
176+
177+
var v = results.sd;
178+
// returns <number>
179+
```
180+
181+
#### Float32Results.prototype.toString( \[options] )
182+
183+
Serializes a results object to a formatted string.
184+
185+
```javascript
186+
var results = new Float32Results();
187+
// returns {...}
188+
189+
// ...
190+
191+
var v = results.toString();
192+
// returns <string>
193+
```
194+
195+
The method supports the following options:
196+
197+
- **digits**: number of digits to display after decimal points. Default: `4`.
198+
- **decision**: boolean indicating whether to show the test decision. Default: `true`.
199+
200+
Example output:
201+
202+
```text
203+
204+
One-sample Z-test
205+
206+
Alternative hypothesis: True mean is less than 1.0
207+
208+
pValue: 0.0406
209+
statistic: 9.9901
210+
95% confidence interval: [9.7821, 10.4451]
211+
212+
Test Decision: Reject null in favor of alternative at 5% significance level
213+
214+
```
215+
216+
#### Float32Results.prototype.toJSON( \[options] )
217+
218+
Serializes a results object as a JSON object.
219+
220+
```javascript
221+
var results = new Float32Results();
222+
// returns {...}
223+
224+
// ...
225+
226+
var v = results.toJSON();
227+
// returns {...}
228+
```
229+
230+
`JSON.stringify()` implicitly calls this method when stringifying a results instance.
231+
232+
#### Float32Results.prototype.toDataView()
233+
234+
Returns a [`DataView`][@stdlib/array/dataview] of a results object.
235+
236+
```javascript
237+
var results = new Float32Results();
238+
// returns {...}
239+
240+
// ...
241+
242+
var v = results.toDataView();
243+
// returns <DataView>
244+
```
245+
246+
</section>
247+
248+
<!-- /.usage -->
249+
250+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
251+
252+
<section class="notes">
253+
254+
## Notes
255+
256+
- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing one-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation.
257+
258+
</section>
259+
260+
<!-- /.notes -->
261+
262+
<!-- Package usage examples. -->
263+
264+
<section class="examples">
265+
266+
## Examples
267+
268+
<!-- eslint no-undef: "error" -->
269+
270+
```javascript
271+
var Float32Array = require( '@stdlib/array/float32' );
272+
var Results = require( '@stdlib/stats/base/ztest/one-sample/results/float32' );
273+
274+
var results = new Results({
275+
'rejected': true,
276+
'alpha': 0.05,
277+
'pValue': 0.3364,
278+
'statistic': 11.7586,
279+
'nullValue': 0.0,
280+
'sd': 0.4563,
281+
'ci': new Float32Array( [ 9.9983, 11.4123 ] ),
282+
'alternative': 'two-sided'
283+
});
284+
285+
var str = results.toString({
286+
'format': 'linear'
287+
});
288+
console.log( str );
289+
```
290+
291+
</section>
292+
293+
<!-- /.examples -->
294+
295+
<!-- 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. -->
296+
297+
<section class="references">
298+
299+
</section>
300+
301+
<!-- /.references -->
302+
303+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
304+
305+
<section class="related">
306+
307+
</section>
308+
309+
<!-- /.related -->
310+
311+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
312+
313+
<section class="links">
314+
315+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct
316+
317+
[@stdlib/array/dataview]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dataview
318+
319+
[@stdlib/array/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float32
320+
321+
[@stdlib/array/buffer]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/buffer
322+
323+
</section>
324+
325+
<!-- /.links -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 isObject = require( '@stdlib/assert/is-object' );
25+
var pkg = require( './../package.json' ).name;
26+
var Float32Results = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+'::constructor,new', function benchmark( b ) {
32+
var v;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
v = new Float32Results();
38+
if ( typeof v !== 'object' ) {
39+
b.fail( 'should return an object' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isObject( v ) ) {
44+
b.fail( 'should return an object' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
49+
50+
bench( pkg+'::constructor,no_new', function benchmark( b ) {
51+
var results;
52+
var v;
53+
var i;
54+
55+
results = Float32Results;
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
v = results();
60+
if ( typeof v !== 'object' ) {
61+
b.fail( 'should return an object' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isObject( v ) ) {
66+
b.fail( 'should return an object' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});

0 commit comments

Comments
 (0)