Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions lib/node_modules/@stdlib/stats/fligner-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ limitations under the License.
var flignerTest = require( '@stdlib/stats/fligner-test' );
```

#### flignerTest( a\[,b,...,k]\[, opts] )
#### flignerTest( a\[,b,...,k]\[, options] )

For input arrays `a`, `b`, ... holding numeric observations, this function calculates the Fligner-Killeen test, which tests the null hypothesis that the variances in all `k` groups are the same.

Expand All @@ -46,7 +46,9 @@ 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 ];

var out = flignerTest( x, y, z );
var res = flignerTest( x, y, z );

var o = res.toJSON();
/* returns
{
'rejected': false,
Expand Down Expand Up @@ -106,23 +108,34 @@ var out = flignerTest( 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.

The returned object comes with a `.toString()` method which when invoked will print a formatted output of the results of the hypothesis test. `toString` 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.

```javascript
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 ];

var out = flignerTest( x, y, z );
console.log( out.print() );
/* =>
var table = out.toString();
/* returns
Fligner-Killeen test of homogeneity of variances

Null hypothesis: The variances in all groups are the same.
Null hypothesis: The variances in all groups are the same

pValue: 0.0739
statistic: 5.2092
df: 2
degrees of freedom: 2

Test Decision: Fail to reject null in favor of alternative at 5% significance level
*/
Expand Down Expand Up @@ -158,15 +171,15 @@ var out = flignerTest( x, y, z );
}
*/

var table = out.print();
var table = out.toString();
/* returns
Fligner-Killeen test of homogeneity of variances

Null hypothesis: The variances in all groups are the same.
Null hypothesis: The variances in all groups are the same

pValue: 0.0739
statistic: 5.2092
df: 2
degrees of freedom: 2

Test Decision: Fail to reject null in favor of alternative at 5% significance level
*/
Expand Down
19 changes: 15 additions & 4 deletions lib/node_modules/@stdlib/stats/fligner-test/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand All @@ -50,7 +53,11 @@
> 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 );
> var o = out.toJSON()
{...}
> out.toString()
<string>

> var arr = [ 2.9, 3.0, 2.5, 2.6, 3.2,
... 3.8, 2.7, 4.0, 2.4,
Expand All @@ -61,7 +68,11 @@
... 'b', 'b', 'b', 'b',
... 'c', 'c', 'c', 'c', 'c'
... ];
> out = {{alias}}( arr, { 'groups': groups } )
> out = {{alias}}( arr, { 'groups': groups } );
> o = out.toJSON()
{...}
> out.toString()
<string>

See Also
--------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Array of group indicators.
*/
groups?: Array<any>;

Check warning on line 37 in lib/node_modules/@stdlib/stats/fligner-test/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -72,9 +72,14 @@
df: number;

/**
* Function to print formatted output.
* Serializes results as formatted test output.
*/
print: Function;
toString: Function; // FIXME: provide better type

/**
* Serializes results as JSON.
*/
toJSON: Function; // FIXME: provide better type
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
51 changes: 10 additions & 41 deletions lib/node_modules/@stdlib/stats/fligner-test/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,20 @@

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 qnorm = require( '@stdlib/stats/base/dists/normal/quantile' );
var chisqCDF = require( '@stdlib/stats/base/dists/chisquare/cdf' );
var group = require( '@stdlib/utils/group' );
var ranks = require( '@stdlib/stats/ranks' );
var abs = require( '@stdlib/math/base/special/abs' );
var abs = require( '@stdlib/math/strided/special/abs' );
var pow = require( '@stdlib/math/base/special/pow' );
var indexOf = require( '@stdlib/utils/index-of' );
var format = require( '@stdlib/string/format' );
var filled = require( '@stdlib/array/base/filled' );
var Float64Array = require( '@stdlib/array/float64' );
var median = require( './median.js' );
var validate = require( './validate.js' );
var print = require( './print.js' ); // eslint-disable-line stdlib/no-redeclare


// FUNCTIONS //

/**
* Returns an array of a chosen length filled with the supplied value.
*
* @private
* @param {*} val - value to repeat
* @param {NonNegativeInteger} len - array length
* @returns {Array} filled array
*/
function repeat( val, len ) {
var out = new Array( len );
var i;

for ( i = 0; i < len; i++ ) {
out[ i ] = val;
}
return out;
}
var Results = require( './results.js' );


// MAIN //
Expand Down Expand Up @@ -102,7 +82,6 @@ function fligner() {
var stat;
var err;
var loc;
var out;
var df;
var M2;
var a;
Expand Down Expand Up @@ -137,7 +116,7 @@ function fligner() {
groups = [];
for ( i = 0; i < ngroups; i++ ) {
args.push( arguments[ i ] );
groups = groups.concat( repeat( i, arguments[ i ].length ) );
groups = groups.concat( filled( i, arguments[ i ].length ) );
}
}
if ( opts.alpha === void 0 ) {
Expand All @@ -163,15 +142,13 @@ function fligner() {
x = x.concat( args[ i ] );
}
n = x.length;
xabs = new Array( n );
for ( i = 0; i < n; i++ ) {
xabs[ i ] = abs( x[ i ] );
}
xabs = new Float64Array( n );
abs( n, 'float64', x, 1, 'float64', xabs, 1 );
scores = ranks( xabs );
a = new Array( n );
a = new Float64Array( n );
mean = 0.0;
M2 = 0.0;
sums = repeat( 0.0, ngroups );
sums = filled( 0.0, ngroups );
for ( i = 0; i < n; i++ ) {
a[ i ] = qnorm( ( 1.0 + ( scores[ i ]/(n+1) ) ) / 2.0, 0.0, 1.0 );
sums[ ( levels ) ? indexOf( levels, groups[i] ) : groups[i] ] += a[ i ];
Expand All @@ -188,15 +165,7 @@ function fligner() {
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', 'Fligner-Killeen test of homogeneity of variances' );
setReadOnly( out, 'print', print );
return out;
return new Results( pval, opts.alpha, stat, df );
}


Expand Down
93 changes: 0 additions & 93 deletions lib/node_modules/@stdlib/stats/fligner-test/lib/print.js

This file was deleted.

Loading