|
| 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 | +# structFactory |
| 22 | + |
| 23 | +> Create a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. |
| 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 structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### structFactory( dtype ) |
| 44 | + |
| 45 | +Returns a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var Struct = structFactory( 'float64' ); |
| 49 | +// returns <Function> |
| 50 | + |
| 51 | +var s = new Struct(); |
| 52 | +// returns <Struct> |
| 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 [`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. |
| 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 resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); |
| 85 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 86 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 87 | +var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); |
| 88 | + |
| 89 | +var Struct = structFactory( 'float64' ); |
| 90 | +var results = new Struct({ |
| 91 | + 'rejected': true, |
| 92 | + 'alpha': 0.05, |
| 93 | + 'pValue': 0.0132, |
| 94 | + 'statistic': 2.4773, |
| 95 | + 'nullValue': 0.0, |
| 96 | + 'xmean': 3.7561, |
| 97 | + 'ymean': 3.0129, |
| 98 | + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), |
| 99 | + 'alternative': resolveEnum( 'two-sided' ) |
| 100 | +}); |
| 101 | + |
| 102 | +var str = results.toString({ |
| 103 | + 'format': 'linear' |
| 104 | +}); |
| 105 | +console.log( str ); |
| 106 | + |
| 107 | +Struct = structFactory( 'float32' ); |
| 108 | +results = new Struct({ |
| 109 | + 'rejected': true, |
| 110 | + 'alpha': 0.05, |
| 111 | + 'pValue': 0.0132, |
| 112 | + 'statistic': 2.4773, |
| 113 | + 'nullValue': 0.0, |
| 114 | + 'xmean': 3.7561, |
| 115 | + 'ymean': 3.0129, |
| 116 | + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), |
| 117 | + 'alternative': resolveEnum( 'two-sided' ) |
| 118 | +}); |
| 119 | + |
| 120 | +str = results.toString({ |
| 121 | + 'format': 'linear' |
| 122 | +}); |
| 123 | +console.log( str ); |
| 124 | +``` |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.examples --> |
| 129 | + |
| 130 | +<!-- 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. --> |
| 131 | + |
| 132 | +<section class="references"> |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.references --> |
| 137 | + |
| 138 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 139 | + |
| 140 | +<section class="related"> |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.related --> |
| 145 | + |
| 146 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 147 | + |
| 148 | +<section class="links"> |
| 149 | + |
| 150 | +[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct |
| 151 | + |
| 152 | +</section> |
| 153 | + |
| 154 | +<!-- /.links --> |
0 commit comments