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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | 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 10x 10x 10x 10x 10x 10x 10x 10x 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 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 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 33x 8x 8x 33x 12x 11x 11x 1x 1x 33x 12x 11x 11x 1x 1x 33x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 35x 4x 4x 4x 5x 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 | /** * @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. */ /* eslint-disable no-invalid-this, no-restricted-syntax */ '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 roundn = require( '@stdlib/math/base/special/roundn' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); var format = require( '@stdlib/string/format' ); // MAIN // /** * Returns a results object. * * @private * @constructor * @param {number} pValue - p-value * @param {number} alpha - significance * @param {number} statistic - test statistic * @param {number} df - degrees of freedom * @returns {Results} results object * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * // returns <Results> */ function Results( pValue, alpha, statistic, df ) { if ( !(this instanceof Results) ) { return new Results( pValue, alpha, statistic, df ); } this._pValue = pValue; this._alpha = alpha; this._statistic = statistic; this._df = df; return this; } /** * Significance level. * * @private * @name alpha * @memberof Results.prototype * @type {number} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var alpha = res.alpha; * // returns 0.1 */ setReadOnlyAccessor( Results.prototype, 'alpha', function get() { return this._alpha; }); /** * Degrees of freedom. * * @private * @name df * @memberof Results.prototype * @type {number} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var df = res.df; * // returns 1 */ setReadOnlyAccessor( Results.prototype, 'df', function get() { return this._df; }); /** * Test name. * * @private * @name method * @memberof Results.prototype * @type {string} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var method = res.method; * // returns 'Bartlett\'s test of equal variances' */ setReadOnly( Results.prototype, 'method', 'Bartlett\'s test of equal variances' ); /** * Test p-value. * * @private * @name pValue * @memberof Results.prototype * @type {number} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var pval = res.pValue; * // returns 0.0719 */ setReadOnlyAccessor( Results.prototype, 'pValue', function get() { return this._pValue; }); /** * Boolean indicating the test decision. * * @private * @name rejected * @memberof Results.prototype * @type {boolean} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var bool = res.rejected; * // returns true */ setReadOnlyAccessor( Results.prototype, 'rejected', function get() { return ( this._pValue <= this._alpha ); }); /** * Test statistic. * * @private * @name statistic * @memberof Results.prototype * @type {number} * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var stat = res.statistic; * // returns 3.24 */ setReadOnlyAccessor( Results.prototype, 'statistic', function get() { return this._statistic; }); /** * Serializes a results object as a string. * * ## Notes * * - Example output: * * ```text * * Chi-square independence test * * Null hypothesis: the two variables are independent * * pValue: 0.0719 * statistic: 3.24 * degrees of freedom: 1 * * Test Decision: Reject null in favor of alternative at 10% significance level * * ``` * * @private * @name toString * @memberof Results.prototype * @type {Function} * @param {Options} [opts] - options object * @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point * @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 res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var str = res.toString(); * // returns <string> */ setReadOnly( Results.prototype, 'toString', function toString( opts ) { var decision; var dgts; var out; dgts = 4; decision = true; if ( arguments.length > 0 ) { 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; } } out = [ this.method, '', '', 'Null hypothesis: The variances in all groups are the same.', '', '', ' pValue: ' + roundn( this._pValue, -dgts ), ' statistic: ' + roundn( this._statistic, -dgts ), ' degrees of freedom: ' + this._df, '' ]; if ( decision ) { out.push( 'Test Decision: ' + ( ( this.rejected ) ? 'Reject' : 'Fail to reject' ) + ' null in favor of alternative at ' + (this._alpha*100.0) + '% significance level' ); out.push( '' ); } return out.join( '\n' ); }); /** * Serializes a results object as a JSON object. * * ## Notes * * - `JSON.stringify()` implicitly calls this method when stringifying a `Results` instance. * * @private * @name toJSON * @memberof Results.prototype * @type {Function} * @returns {Object} serialized object * * @example * var res = new Results( 0.0719, 0.1, 3.24, 1 ); * * var o = res.toJSON(); * // returns { 'rejected': true, 'alpha': 0.1, 'pValue': 0.0719, 'df': 1, ... } */ setReadOnly( Results.prototype, 'toJSON', function toJSON() { return { 'rejected': this.rejected, 'alpha': this._alpha, 'pValue': this._pValue, 'df': this._df, 'statistic': this._statistic, 'method': this.method }; }); // EXPORTS // module.exports = Results; |