From 827699ba26706f3338469e0504c2ffe44152247a Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 14 Mar 2025 18:10:23 -0400 Subject: [PATCH 1/2] feat!: refactor implementation to return a class instance --- 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: na - task: lint_repl_help status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/bartlett-test/README.md | 26 +- .../bartlett-test/benchmark/benchmark.js | 35 +-- .../@stdlib/stats/bartlett-test/docs/repl.txt | 15 +- .../stats/bartlett-test/docs/types/index.d.ts | 10 +- .../stats/bartlett-test/examples/index.js | 2 +- .../@stdlib/stats/bartlett-test/lib/main.js | 24 +- .../@stdlib/stats/bartlett-test/lib/print.js | 93 ------ .../stats/bartlett-test/lib/results.js | 284 ++++++++++++++++++ .../stats/bartlett-test/lib/validate.js | 6 +- .../stats/bartlett-test/lib/variance.js | 52 ---- .../@stdlib/stats/bartlett-test/test/test.js | 47 ++- 11 files changed, 379 insertions(+), 215 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/bartlett-test/lib/print.js create mode 100644 lib/node_modules/@stdlib/stats/bartlett-test/lib/results.js delete mode 100644 lib/node_modules/@stdlib/stats/bartlett-test/lib/variance.js diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/README.md b/lib/node_modules/@stdlib/stats/bartlett-test/README.md index 91b503e2db62..e869873ea9bc 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/README.md +++ b/lib/node_modules/@stdlib/stats/bartlett-test/README.md @@ -55,9 +55,9 @@ where `N` is the total number of observations, `S_i` are the biased group-level var bartlettTest = require( '@stdlib/stats/bartlett-test' ); ``` -#### bartlettTest( a\[,b,...,k]\[, opts] ) +#### bartlettTest( a\[,b,...,k]\[, options] ) -For input arrays `a`, `b`, ... holding numeric observations, this function calculates Bartlett’s test, which tests the null hypothesis that the variances in all `k` groups are the same. +For input arrays `a`, `b`, ... holding numeric observations, this function calculates Bartlett’s test, which tests the null hypothesis that the variances in all `k` groups are the same. ```javascript // Data from Hollander & Wolfe (1973), p. 116: @@ -125,7 +125,21 @@ var out = bartlettTest( arr, { }); ``` -The returned object comes with a `.print()` method which when invoked will print a formatted output of the results of the hypothesis test. `print` accepts a `digits` option that controls the number of decimal digits displayed for the outputs and a `decision` option, which when set to `false` will hide the test decision. +The function returns a results `object` having the following properties: + +- **alpha**: significance level. +- **rejected**: `boolean` indicating the test decision. +- **pValue**: test p-value. +- **statistic**: test statistic. +- **df**: degrees of freedom. +- **method**: test name. +- **toString**: serializes results as formatted test output. +- **toJSON**: serializes results as a JSON object. + +To print formatted test output, invoke the `toString` method. The method accepts the following options: + +- **digits**: number of displayed decimal digits. Default: `4`. +- **decision**: `boolean` indicating whether to show the test decision. Default: `true`. ```javascript var x = [ 2.9, 3.0, 2.5, 2.6, 3.2 ]; @@ -133,8 +147,8 @@ var y = [ 3.8, 2.7, 4.0, 2.4 ]; var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; var out = bartlettTest( x, y, z ); -console.log( out.print() ); -/* => +var table = res.toString(); +/* e.g., returns Bartlett's test of equal variances Null hypothesis: The variances in all groups are the same. @@ -177,7 +191,7 @@ var out = bartlettTest( x, y, z ); } */ -var table = out.print(); +var table = out.toString(); /* returns Bartlett's test of equal variances diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/bartlett-test/benchmark/benchmark.js index bc725cddbdf1..2e19e89d7636 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/bartlett-test/benchmark/benchmark.js @@ -21,10 +21,12 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); var randu = require( '@stdlib/random/base/randu' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isObject = require( '@stdlib/assert/is-object' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var bartlettTest = require( './../lib' ); @@ -33,21 +35,14 @@ var bartlettTest = require( './../lib' ); bench( pkg, function benchmark( b ) { var result; - var len; var x; var y; var z; var i; - x = new Array( 50 ); - y = new Array( 50 ); - z = new Array( 50 ); - len = x.length; - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*50.0 ); - y[ i ] = ( randu()*50.0 ) + 10.0; - z[ i ] = ( randu()*50.0 ) + 20.0; - } + x = uniform( 50, 0.0, 50.0 ); + y = uniform( 50, 10.0, 60.0 ); + z = uniform( 50, 20.0, 70.0 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -72,11 +67,10 @@ bench( pkg+'::groups', function benchmark( b ) { var len; var i; - vals = new Array( 150 ); - group = new Array( 150 ); - len = vals.length; + len = 150; + group = discreteUniform( 150, 0, 2 ); + vals = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - group[ i ] = discreteUniform( 0, 2 ); vals[ i ] = ( randu()*50.0 ) + ( 10.0*group[ i ] ); } @@ -98,7 +92,7 @@ bench( pkg+'::groups', function benchmark( b ) { b.end(); }); -bench( pkg+':print', function benchmark( b ) { +bench( pkg+':toString', function benchmark( b ) { var digits; var result; var output; @@ -107,11 +101,10 @@ bench( pkg+':print', function benchmark( b ) { var len; var i; - vals = new Array( 100 ); - group = new Array( 100 ); - len = vals.length; + len = 100; + group = discreteUniform( len, 0, 2 ); + vals = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - group[ i ] = discreteUniform( 0, 2 ); vals[ i ] = ( randu()*50.0 ) + ( 10.0*group[ i ] ); } result = bartlettTest( vals, { @@ -121,7 +114,7 @@ bench( pkg+':print', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { digits = ( i % 8 ) + 1; - output = result.print({ + output = result.toString({ 'digits': digits }); if ( typeof output !== 'string' ) { diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/docs/repl.txt b/lib/node_modules/@stdlib/stats/bartlett-test/docs/repl.txt index 9a694ae15af9..842e16011262 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/bartlett-test/docs/repl.txt @@ -20,7 +20,7 @@ Returns ------- out: Object - Test result object. + Test results object. out.alpha: number Significance level. @@ -40,8 +40,11 @@ out.df: Object Degrees of freedom. - out.print: Function - Function to print formatted output. + out.toString: Function + Serializes results as formatted output. + + out.toJSON: Function + Serializes results as JSON. Examples -------- @@ -50,7 +53,8 @@ > var y = [ 3.8, 2.7, 4.0, 2.4 ]; > var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; - > var out = {{alias}}( x, y, z ) + > var out = {{alias}}( x, y, z ); + > out.toString() > var arr = [ 2.9, 3.0, 2.5, 2.6, 3.2, ... 3.8, 2.7, 4.0, 2.4, @@ -61,7 +65,8 @@ ... 'b', 'b', 'b', 'b', ... 'c', 'c', 'c', 'c', 'c' ... ]; - > out = {{alias}}( arr, { 'groups': groups } ) + > out = {{alias}}( arr, { 'groups': groups } ); + > out.toString() See Also -------- diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/bartlett-test/docs/types/index.d.ts index bbc9d1e9c474..73c322eeab97 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/bartlett-test/docs/types/index.d.ts @@ -22,6 +22,7 @@ import { NumericArray } from '@stdlib/types/array'; + /** * Interface defining function options. */ @@ -72,9 +73,14 @@ interface Results { df: number; /** - * Function to print formatted output. + * Serializes results as formatted test output. + */ + toString: Function; // FIXME: provide better type + + /** + * Serializes results as JSON. */ - print: Function; + toJSON: Function; // FIXME: provide better type } /** diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/examples/index.js b/lib/node_modules/@stdlib/stats/bartlett-test/examples/index.js index 0deb05522eb3..e095f2c0a9bd 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/examples/index.js +++ b/lib/node_modules/@stdlib/stats/bartlett-test/examples/index.js @@ -30,5 +30,5 @@ console.log( 'Output object: ' ); console.dir( out ); console.log( '\n' ); -var table = out.print(); +var table = out.toString(); console.log( table ); diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/lib/main.js b/lib/node_modules/@stdlib/stats/bartlett-test/lib/main.js index b272e9edae37..975d371c83c8 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/lib/main.js +++ b/lib/node_modules/@stdlib/stats/bartlett-test/lib/main.js @@ -22,15 +22,16 @@ var isCollection = require( '@stdlib/assert/is-collection' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); var objectKeys = require( '@stdlib/utils/keys' ); var format = require( '@stdlib/string/format' ); var chisqCDF = require( '@stdlib/stats/base/dists/chisquare/cdf' ); var group = require( '@stdlib/utils/group' ); var ln = require( '@stdlib/math/base/special/ln' ); -var variance = require( './variance.js' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dvariance = require( '@stdlib/stats/base/dvariance' ); var validate = require( './validate.js' ); -var print = require( './print.js' ); // eslint-disable-line stdlib/no-redeclare +var Results = require( './results.js' ); // MAIN // @@ -74,7 +75,6 @@ function bartlett() { var arg; var err; var lnv; - var out; var df; var n; var v; @@ -110,8 +110,8 @@ function bartlett() { ninvSum = 0.0; vSum = 0.0; lnv = 0.0; - n = new Array( ngroups ); - v = n.slice(); + n = new Int32Array( ngroups ); + v = new Float64Array( ngroups ); for ( i = 0; i < ngroups; i++ ) { arg = args[ i ]; if ( !isCollection( arg ) ) { @@ -123,7 +123,7 @@ function bartlett() { n[ i ] = arg.length - 1; nSum += n[ i ]; ninvSum += 1.0 / n[ i ]; - v[ i ] = variance( arg ); + v[ i ] = dvariance( arg.length, 1, arg, 1 ); vSum += ( n[ i ] * v[ i ] ); lnv += n[ i ] * ln( v[ i ] ); } @@ -142,15 +142,7 @@ function bartlett() { df = ngroups - 1; pval = 1.0 - chisqCDF( stat, df ); - out = {}; - setReadOnly( out, 'rejected', pval <= alpha ); - setReadOnly( out, 'alpha', alpha ); - setReadOnly( out, 'pValue', pval ); - setReadOnly( out, 'statistic', stat ); - setReadOnly( out, 'df', df ); - setReadOnly( out, 'method', 'Bartlett\'s test of equal variances' ); - setReadOnly( out, 'print', print ); - return out; + return new Results( pval, alpha, stat, df ); } diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/lib/print.js b/lib/node_modules/@stdlib/stats/bartlett-test/lib/print.js deleted file mode 100644 index 5b29f6574273..000000000000 --- a/lib/node_modules/@stdlib/stats/bartlett-test/lib/print.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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' ); -var roundn = require( '@stdlib/math/base/special/roundn' ); - - -// MAIN // - -/** -* Pretty-print output of test. -* -* @param {Object} [opts] - options object -* @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point -* @param {boolean} [opts.decision=true] - boolean indicating whether to print the test decision -* @throws {TypeError} options must be an object -* @throws {TypeError} must provide valid options -* @returns {string} formatted output -*/ -function print( opts ) { // eslint-disable-line stdlib/no-redeclare - /* eslint-disable no-invalid-this */ - var decision; - var dgts; - var str; - - dgts = 4; - decision = true; - if ( arguments.length > 0 ) { - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. First argument must be 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; - } - } - - str = ''; - str += this.method; - str += '\n\n'; - str += 'Null hypothesis: The variances in all groups are the same.'; - str += '\n\n'; - str += ' pValue: ' + roundn( this.pValue, -dgts ) + '\n'; - str += ' statistic: ' + roundn( this.statistic, -dgts ) + '\n'; - str += ' df: ' + roundn( this.df, -dgts ); - str += '\n\n'; - if ( decision ) { - str += 'Test Decision: '; - if ( this.rejected ) { - str += 'Reject null in favor of alternative at ' + (this.alpha*100) + '% significance level'; - } else { - str += 'Fail to reject null in favor of alternative at ' + (this.alpha*100) + '% significance level'; - } - str += '\n'; - } - return str; -} - - -// EXPORTS // - -module.exports = print; diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/lib/results.js b/lib/node_modules/@stdlib/stats/bartlett-test/lib/results.js new file mode 100644 index 000000000000..8b258115f599 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/bartlett-test/lib/results.js @@ -0,0 +1,284 @@ +/** +* @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 +*/ +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 +*/ +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; diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/lib/validate.js b/lib/node_modules/@stdlib/stats/bartlett-test/lib/validate.js index 8a415aff7bb1..38dac0bebea1 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/lib/validate.js +++ b/lib/node_modules/@stdlib/stats/bartlett-test/lib/validate.js @@ -20,7 +20,7 @@ // MODULES // -var isArray = require( '@stdlib/assert/is-array' ); +var isCollection = require( '@stdlib/assert/is-collection' ); var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isObject = require( '@stdlib/assert/is-plain-object' ); var isnan = require( '@stdlib/assert/is-nan' ); @@ -52,8 +52,8 @@ function validate( opts, options ) { } if ( hasOwnProp( options, 'groups' ) ) { opts.groups = options.groups; - if ( !isArray( opts.groups ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'groups', opts.groups ) ); + if ( !isCollection( opts.groups ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a collection. Option: `%s`.', 'groups', opts.groups ) ); } } return null; diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/lib/variance.js b/lib/node_modules/@stdlib/stats/bartlett-test/lib/variance.js deleted file mode 100644 index a52a1f2f1b0b..000000000000 --- a/lib/node_modules/@stdlib/stats/bartlett-test/lib/variance.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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'; - -/** -* Computes the unbiased variance of an array. -* -* @private -* @param {NumericArray} arr - input array -* @returns {number} variance -*/ -function variance( arr ) { - var delta; - var mean; - var len; - var M2; - var i; - var x; - - delta = 0.0; - mean = 0.0; - M2 = 0.0; - len = arr.length; - for ( i = 0; i < len; i++ ) { - x = arr[ i ]; - delta = x - mean; - mean += delta / (i+1); - M2 += delta * ( x - mean ); - } - return M2 / ( i - 1 ); -} - - -// EXPORTS // - -module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/test/test.js b/lib/node_modules/@stdlib/stats/bartlett-test/test/test.js index d9c907e7395b..bd7f2b4404b3 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/test/test.js +++ b/lib/node_modules/@stdlib/stats/bartlett-test/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var contains = require( '@stdlib/assert/contains' ); var abs = require( '@stdlib/math/base/special/abs' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -160,7 +161,7 @@ tape( 'the function throws an error if the `groups` option array does not contai } }); -tape( 'the function correctly computes a Kruskal-Wallis test', function test( t ) { +tape( 'the function correctly computes Bartlett’s test', function test( t ) { var expected; var delta; var tol; @@ -184,7 +185,7 @@ tape( 'the function correctly computes a Kruskal-Wallis test', function test( t t.end(); }); -tape( 'the function returns an object with a `.print()` method for printing a formatted output table', function test( t ) { +tape( 'the function returns an object with a `.toString()` method for printing a formatted output table', function test( t ) { var table; var out; @@ -193,19 +194,19 @@ tape( 'the function returns an object with a `.print()` method for printing a fo var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = bartlettTest( x, y, z ); - table = out.print(); + table = out.toString(); t.equal( typeof table, 'string', 'returns a string' ); out = bartlettTest( x, y, z, { 'alpha': 0.01 }); - table = out.print(); + table = out.toString(); t.equal( typeof table, 'string', 'returns a string' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts a `digits` option to control the number of decimal digits displayed', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts a `digits` option to control the number of decimal digits displayed', function test( t ) { var table; var out; @@ -214,14 +215,14 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d var z = [ 6.8, 3.4, 3.7, 5.2, 4.0 ]; out = bartlettTest( x, y, z ); - table = out.print({ + table = out.toString({ 'digits': 6 }); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts a `decision` option to control whether the test result should be displayed', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts a `decision` option to control whether the test result should be displayed', function test( t ) { var table; var out; @@ -230,7 +231,7 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = bartlettTest( x, y, z ); - table = out.print({ + table = out.toString({ 'decision': false }); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); @@ -238,7 +239,7 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts an `options` object', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts an `options` object', function test( t ) { var table; var out; @@ -247,13 +248,13 @@ tape( 'the function returns an object with a `.print()` method that accepts an ` var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = bartlettTest( x, y, z ); - table = out.print( {} ); + table = out.toString( {} ); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that throws an error if `options` is not a simple object', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if `options` is not a simple object', function test( t ) { var values; var out; var i; @@ -282,12 +283,12 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print( value ); + out.toString( value ); }; } }); -tape( 'the function returns an object with a `.print()` method that throws an error if the `digits` option is not a positive integer', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if the `digits` option is not a positive integer', function test( t ) { var values; var out; var i; @@ -319,14 +320,14 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print({ + out.toString({ 'digits': value }); }; } }); -tape( 'the function returns an object with a `.print()` method that throws an error if the `decision` option is not a boolean primitive', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if the `decision` option is not a boolean primitive', function test( t ) { var values; var out; var i; @@ -358,9 +359,23 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print({ + out.toString({ 'decision': value }); }; } }); + +tape( 'the function returns an object with a `.toJSON()` method for serializing the test results object', function test( t ) { + var table; + var out; + + var x = [ 2.9, 3.0, 2.5, 2.6, 3.2 ]; + var y = [ 3.8, 2.7, 4.0, 2.4 ]; + var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; + + out = bartlettTest( x, y, z ); + table = out.toJSON(); + t.strictEqual( isPlainObject( table ), true, 'returns a plain object' ); + t.end(); +}); From a6f768d5c442570f80eababccfea3e14d53523e8 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 14 Mar 2025 21:14:35 -0400 Subject: [PATCH 2/2] docs: update example code --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/bartlett-test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/bartlett-test/README.md b/lib/node_modules/@stdlib/stats/bartlett-test/README.md index e869873ea9bc..313cd40833ca 100644 --- a/lib/node_modules/@stdlib/stats/bartlett-test/README.md +++ b/lib/node_modules/@stdlib/stats/bartlett-test/README.md @@ -147,7 +147,7 @@ var y = [ 3.8, 2.7, 4.0, 2.4 ]; var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; var out = bartlettTest( x, y, z ); -var table = res.toString(); +var table = out.toString(); /* e.g., returns Bartlett's test of equal variances