Skip to content

Commit fb54d44

Browse files
committed
feat: add stats/base/ztest/alternatives
--- 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 981457c commit fb54d44

File tree

14 files changed

+725
-0
lines changed

14 files changed

+725
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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+
# Alternative Hypotheses
22+
23+
> Z-test alternative hypotheses.
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 alternatives = require( '@stdlib/stats/base/ztest/alternatives' );
41+
```
42+
43+
#### alternatives()
44+
45+
Returns a list of Z-test alternative hypotheses.
46+
47+
```javascript
48+
var out = alternatives();
49+
// e.g., returns [ 'two-sided', 'less', 'greater' ]
50+
```
51+
52+
The output array contains the following alternatives:
53+
54+
- `two-sided`: mean is not equal to the null hypothesis value.
55+
- `less`: mean is less than the null hypothesis value.
56+
- `greater`: mean is greater than the null hypothesis value.
57+
58+
</section>
59+
60+
<!-- /.usage -->
61+
62+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
63+
64+
<section class="notes">
65+
66+
</section>
67+
68+
<!-- /.notes -->
69+
70+
<!-- Package usage examples. -->
71+
72+
<section class="examples">
73+
74+
## Examples
75+
76+
<!-- eslint no-undef: "error" -->
77+
78+
```javascript
79+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
80+
var alternatives = require( '@stdlib/stats/base/ztest/alternatives' );
81+
82+
var isAlternative = contains( alternatives() );
83+
84+
var bool = isAlternative( 'two-sided' );
85+
// returns true
86+
87+
bool = isAlternative( 'greater' );
88+
// returns true
89+
90+
bool = isAlternative( 'beep' );
91+
// returns false
92+
```
93+
94+
</section>
95+
96+
<!-- /.examples -->
97+
98+
<!-- C interface documentation. -->
99+
100+
* * *
101+
102+
<section class="c">
103+
104+
## C APIs
105+
106+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
107+
108+
<section class="intro">
109+
110+
</section>
111+
112+
<!-- /.intro -->
113+
114+
<!-- C usage documentation. -->
115+
116+
<section class="usage">
117+
118+
### Usage
119+
120+
```c
121+
#include "stdlib/stats/base/ztest/alternatives.h"
122+
```
123+
124+
#### STDLIB_STATS_ZTEST_ALTERNATIVE
125+
126+
An enumeration of Z-test alternative hypotheses with the following fields:
127+
128+
- **STDLIB_STATS_ZTEST_TWO_SIDED**: mean is not equal to the null hypothesis value.
129+
- **STDLIB_STATS_ZTEST_LESS**: mean is less than the null hypothesis value.
130+
- **STDLIB_STATS_ZTEST_GREATER**: mean is greater than the null hypothesis value.
131+
132+
```c
133+
#include "stdlib/stats/base/ztest/alternatives.h"
134+
135+
const enum STDLIB_STATS_ZTEST_ALTERNATIVE v = STDLIB_STATS_ZTEST_TWO_SIDED;
136+
```
137+
138+
</section>
139+
140+
<!-- /.usage -->
141+
142+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
143+
144+
<section class="notes">
145+
146+
### Notes
147+
148+
- Enumeration constants should be considered opaque values, and one should **not** rely on specific integer values.
149+
150+
</section>
151+
152+
<!-- /.notes -->
153+
154+
<!-- C API usage examples. -->
155+
156+
<section class="examples">
157+
158+
</section>
159+
160+
<!-- /.examples -->
161+
162+
</section>
163+
164+
<!-- /.c -->
165+
166+
<!-- 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. -->
167+
168+
<section class="references">
169+
170+
</section>
171+
172+
<!-- /.references -->
173+
174+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
175+
176+
<section class="related">
177+
178+
</section>
179+
180+
<!-- /.related -->
181+
182+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
183+
184+
<section class="links">
185+
186+
</section>
187+
188+
<!-- /.links -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
25+
var pkg = require( './../package.json' ).name;
26+
var alternatives = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var out;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
out = alternatives();
38+
if ( out.length < 2 ) {
39+
b.fail( 'should return an array' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isStringArray( out ) ) {
44+
b.fail( 'should return an array of strings' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
{{alias}}()
3+
Returns a list of alternative hypotheses.
4+
5+
The output array contains the following alternatives:
6+
7+
- two-sided: mean is not equal to null value.
8+
- less: mean is less than null value.
9+
- greater: mean is larger than null value.
10+
11+
Returns
12+
-------
13+
out: Array<string>
14+
List of alternatives.
15+
16+
Examples
17+
--------
18+
> var out = {{alias}}()
19+
[ 'two-sided', 'less', 'greater' ]
20+
21+
See Also
22+
--------
23+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Returns a list of alternative hypotheses.
23+
*
24+
* @returns list of alternative hypotheses
25+
*
26+
* @example
27+
* var list = alternatives();
28+
* // e.g., returns [ 'two-sided', 'less', 'greater' ]
29+
*/
30+
declare function alternatives(): Array<string>;
31+
32+
33+
// EXPORTS //
34+
35+
export = alternatives;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
import alternatives = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an array of strings...
25+
{
26+
alternatives(); // $ExpectType string[]
27+
}
28+
29+
// The compiler throws an error if the function is provided any arguments...
30+
{
31+
alternatives( 9 ); // $ExpectError
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
22+
var alternatives = require( './../lib' );
23+
24+
var isAlternative = contains( alternatives() );
25+
26+
var bool = isAlternative( 'two-sided' );
27+
console.log( bool );
28+
// => true
29+
30+
bool = isAlternative( 'greater' );
31+
console.log( bool );
32+
// => true
33+
34+
bool = isAlternative( 'beep' );
35+
console.log( bool );
36+
// => false

0 commit comments

Comments
 (0)