Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 30x 9x 9x 30x 11x 10x 10x 1x 1x 30x 10x 8x 8x 2x 2x 30x 8x 35x 2x 2x 35x 1x 1x 35x 35x 5x 5x 35x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 35x 7x 7x 7x 8x 35x 1x 1x 1x 1x 1x | /** * @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); var isObject = require( '@stdlib/assert/is-plain-object' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var format = require( '@stdlib/string/format' ); // MAIN // /** * Serializes a two-sample Z-test results object as a formatted string. * * ## Notes * * - Example output: * * ```text * * Two-sample Z-test * * Alternative hypothesis: True mean is less than 1.0 * * pValue: 0.0406 * statistic: 9.9901 * 95% confidence interval: [9.7821, 10.4451] * * Test Decision: Reject null in favor of alternative at 5% significance level * * ``` * * @param {Object} results - two-sample Z-test results object * @param {Options} [opts] - options object * @param {PositiveInteger} [opts.digits=4] - number of digits to display after decimal points * @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision * @throws {TypeError} options argument must be an object * @throws {TypeError} must provide valid options * @returns {string} serialized results * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var results = { * 'rejected': false, * 'alpha': 0.05, * 'pValue': 0.3364, * 'statistic': 11.7586, * 'nullValue': 0.0, * 'sd': 0.4563, * 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), * 'alternative': 'two-sided', * 'method': 'Two-sample Z-test' * }; * * var str = toString( results ); * // returns <string> */ function toString( results, opts ) { // eslint-disable-line stdlib/no-redeclare var decision; var level; var dgts; var out; var alt; var ci; dgts = 4; decision = true; if ( arguments.length > 1 ) { if ( !isObject( opts ) ) { throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', opts ) ); } if ( hasOwnProp( opts, 'digits' ) ) { if ( !isPositiveInteger( opts.digits ) ) { throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); } dgts = opts.digits; } if ( hasOwnProp( opts, 'decision' ) ) { if ( !isBoolean( opts.decision ) ) { throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) ); } decision = opts.decision; } } switch ( results.alternative ) { case 'less': alt = 'less than'; break; case 'greater': alt = 'greater than'; break; case 'two-sided': default: alt = 'not equal to'; break; } level = ( 1.0 - results.alpha ) * 100; ci = results.ci; out = [ '', results.method, '', format( 'Alternative hypothesis: True mean is %s %0.'+dgts+'f', alt, results.nullValue ), '', format( ' pValue: %0.'+dgts+'f', results.pValue ), format( ' statistic: %0.'+dgts+'f', results.statistic ), format( ' %.'+dgts+'f%% confidence interval: [%0.'+dgts+'f, %0.'+dgts+'f]', level, ci[ 0 ], ci[ 1 ] ), '' ]; if ( decision ) { out.push( format( 'Test Decision: %s null in favor of alternative at %.'+dgts+'f%% significance level', ( results.rejected ) ? 'Reject' : 'Fail to reject', 100-level ) ); out.push( '' ); } return out.join( '\n' ); } // EXPORTS // module.exports = toString; |