Skip to content

Commit 26c8af9

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 6ff148b + c9ff833 commit 26c8af9

File tree

27 files changed

+335
-125
lines changed

27 files changed

+335
-125
lines changed

lib/node_modules/@stdlib/math/base/tools/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ var o = tools;
3939
// returns {...}
4040
```
4141

42+
<!-- <toc pattern="*"> -->
43+
44+
<div class="namespace-toc">
45+
46+
- <span class="signature">[`continuedFraction( generator[, options ] )`][@stdlib/math/base/tools/continued-fraction]</span><span class="delimiter">: </span><span class="description">continued fraction approximation.</span>
47+
- <span class="signature">[`evalpoly( c, x )`][@stdlib/math/base/tools/evalpoly]</span><span class="delimiter">: </span><span class="description">evaluate a polynomial.</span>
48+
- <span class="signature">[`evalrational( P, Q, x )`][@stdlib/math/base/tools/evalrational]</span><span class="delimiter">: </span><span class="description">evaluate a rational function.</span>
49+
- <span class="signature">[`fibpoly( n, x )`][@stdlib/math/base/tools/fibpoly]</span><span class="delimiter">: </span><span class="description">evaluate a Fibonacci polynomial.</span>
50+
- <span class="signature">[`lucaspoly( n, x )`][@stdlib/math/base/tools/lucaspoly]</span><span class="delimiter">: </span><span class="description">evaluate a Lucas polynomial.</span>
51+
- <span class="signature">[`sumSeries( generator[, options ] )`][@stdlib/math/base/tools/sum-series]</span><span class="delimiter">: </span><span class="description">compute the sum of an infinite series.</span>
52+
53+
</div>
54+
55+
<!-- </toc> -->
56+
4257
</section>
4358

4459
<!-- /.usage -->
@@ -64,6 +79,22 @@ console.log( getKeys( tools ) );
6479

6580
<section class="links">
6681

82+
<!-- <toc-links> -->
83+
84+
[@stdlib/math/base/tools/continued-fraction]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/continued-fraction
85+
86+
[@stdlib/math/base/tools/evalpoly]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/evalpoly
87+
88+
[@stdlib/math/base/tools/evalrational]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/evalrational
89+
90+
[@stdlib/math/base/tools/fibpoly]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/fibpoly
91+
92+
[@stdlib/math/base/tools/lucaspoly]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/lucaspoly
93+
94+
[@stdlib/math/base/tools/sum-series]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/tools/sum-series
95+
96+
<!-- </toc-links> -->
97+
6798
</section>
6899

69100
<!-- /.links -->

lib/node_modules/@stdlib/math/stats/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,39 @@ var stats = statistics;
3939
// returns {...}
4040
```
4141

42+
The namespace exposes the following statistical tests:
43+
44+
<!-- <toc pattern="+(*test*|chi2gof|anova1)"> -->
45+
46+
<div class="namespace-toc">
47+
48+
- <span class="signature">[`anova1( x, factor[, opts] )`][@stdlib/math/stats/anova1]</span><span class="delimiter">: </span><span class="description">perform a one-way analysis of variance.</span>
49+
- <span class="signature">[`chi2gof( x, y[, ...params][, opts] )`][@stdlib/math/stats/chi2gof]</span><span class="delimiter">: </span><span class="description">perform a chi-square goodness-of-fit test.</span>
50+
- <span class="signature">[`kstest( x, y[, ...params][, opts] )`][@stdlib/math/stats/kstest]</span><span class="delimiter">: </span><span class="description">one-sample Kolmogorov-Smirnov goodness-of-fit test.</span>
51+
- <span class="signature">[`pcorrtest( x, y[, opts] )`][@stdlib/math/stats/pcorrtest]</span><span class="delimiter">: </span><span class="description">compute a Pearson product-moment correlation test between paired samples.</span>
52+
- <span class="signature">[`ttest( x[, y][, opts] )`][@stdlib/math/stats/ttest]</span><span class="delimiter">: </span><span class="description">one-sample and paired Student's t-Test.</span>
53+
- <span class="signature">[`ttest2( x, y[, opts] )`][@stdlib/math/stats/ttest2]</span><span class="delimiter">: </span><span class="description">two-sample Student's t-Test.</span>
54+
- <span class="signature">[`ztest( x, sigma[, opts] )`][@stdlib/math/stats/ztest]</span><span class="delimiter">: </span><span class="description">one-sample z-Test.</span>
55+
- <span class="signature">[`ztest2( x, y, sigmax, sigmay[, opts] )`][@stdlib/math/stats/ztest2]</span><span class="delimiter">: </span><span class="description">two-sample z-Test.</span>
56+
57+
</div>
58+
59+
<!-- </toc> -->
60+
61+
In addition, it contains an assortment of functions for computing statistics incrementally as part of the `incr` sub-namespace.
62+
63+
Other statistical functions included are:
64+
65+
<!-- <toc pattern="*" ignore="+(*test*|chi2gof|anova1)" ignore="incr"> -->
66+
67+
<div class="namespace-toc">
68+
69+
- <span class="signature">[`lowess( x, y[, opts] )`][@stdlib/math/stats/lowess]</span><span class="delimiter">: </span><span class="description">locally-weighted polynomial regression via the LOWESS algorithm.</span>
70+
71+
</div>
72+
73+
<!-- </toc> -->
74+
4275
</section>
4376

4477
<!-- /.usage -->
@@ -64,6 +97,28 @@ console.log( getKeys( statistics ) );
6497

6598
<section class="links">
6699

100+
<!-- <toc-links> -->
101+
102+
[@stdlib/math/stats/lowess]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/lowess
103+
104+
[@stdlib/math/stats/anova1]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/anova1
105+
106+
[@stdlib/math/stats/chi2gof]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/chi2gof
107+
108+
[@stdlib/math/stats/kstest]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/kstest
109+
110+
[@stdlib/math/stats/pcorrtest]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/pcorrtest
111+
112+
[@stdlib/math/stats/ttest]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/ttest
113+
114+
[@stdlib/math/stats/ttest2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/ttest2
115+
116+
[@stdlib/math/stats/ztest]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/ztest
117+
118+
[@stdlib/math/stats/ztest2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/stats/ztest2
119+
120+
<!-- </toc-links> -->
121+
67122
</section>
68123

69124
<!-- /.links -->

lib/node_modules/@stdlib/math/stats/anova1/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
var anova1 = require( '@stdlib/math/stats/anova1' );
3131
```
3232

33-
### anova1( x, factor\[, opts] )
33+
#### anova1( x, factor\[, opts] )
3434

3535
For an [array][mdn-array] or [typed array][mdn-typed-array] of numeric values `x` and an [array][mdn-array] of classifications `factor`, a one-way analysis of variance is performed. The hypotheses are given as follows:
3636

@@ -49,7 +49,7 @@ x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
4949
y = [ 'Treatment A', 'Treatment B', 'Treatment C', 'Control', 'Treatment A', 'Treatment B', 'Treatment C', 'Control', 'Treatment A', 'Treatment B', 'Treatment C', 'Control' ];
5050

5151
// Making the object
52-
out = anova1(x, y);
52+
out = anova1( x, y );
5353
/* returns
5454
{ 'treatmentDf': 11,
5555
'treatmentSS': 15,
@@ -80,7 +80,7 @@ x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
8080
y = [ 'Treatment A', 'Treatment B', 'Treatment C', 'Control', 'Treatment A', 'Treatment B', 'Treatment C', 'Control', 'Treatment A', 'Treatment B', 'Treatment C', 'Control' ];
8181

8282
// Making the object
83-
out = anova1(x, y);
83+
out = anova1( x, y );
8484
console.log( out.print() );
8585
/* =>
8686
One-Way anova1

lib/node_modules/@stdlib/math/stats/anova1/docs/repl.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
{{alias}}( x, factor[, opts] )
2+
{{alias}}( x, factor[, options] )
33
Performs a one-way analysis of variance.
44

55
Parameters
66
----------
77
x: Array<number>
88
Measured values.
99

10-
y: Array
10+
factor: Array
1111
Array of treatments.
1212

1313
options: Object (optional)
@@ -23,13 +23,13 @@
2323
Test result object.
2424

2525
out.alpha: number
26-
Used significance level.
26+
Significance level.
2727

2828
out.rejected: boolean
2929
Test decision.
3030

3131
out.pValue: number
32-
P-value of the test.
32+
p-value of the test.
3333

3434
out.statistic: number
3535
Value of test statistic.
@@ -52,7 +52,7 @@
5252
out.errorDf: number
5353
Error degrees of freedom.
5454

55-
out.treatmentSS: number
55+
out.errorSS: number
5656
Error sum of squares.
5757

5858
out.errorMSS: number
@@ -68,7 +68,7 @@
6868
... 'control', 'treatA', 'treatB', 'treatC', 'control',
6969
... 'treatA', 'treatB', 'treatC', 'control', 'treatA', 'treatB', 'treatC'
7070
... ];
71-
> var out = {{alias}}(x, f);
71+
> var out = {{alias}}( x, f )
7272
{...}
7373

7474
See Also

lib/node_modules/@stdlib/math/stats/anova1/lib/anova1.js

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var defaults = require( './defaults.json' );
3030
var validate = require( './validate.js' );
3131
var unique = require( './unique.js' );
3232
var meanTable = require( './mean_table.js' );
33+
var mean = require( './mean.js' );
3334
var prettyPrint = require( './print.js' );
3435

3536

@@ -59,68 +60,54 @@ function anova1( x, factor, options ) {
5960
var sumSqError;
6061
var treatment; // Index variable
6162
var grandMean;
63+
var nGroups;
6264
var fScore;
6365
var treats;
6466
var means;
6567
var numDf;
6668
var denDf;
69+
var nobs;
6770
var pVal;
6871
var opts;
6972
var err;
7073
var out;
7174
var sq;
7275
var i;
7376

74-
// Initialize all vars
75-
grandMean = 0.0;
76-
sumSqTotal = 0.0;
77-
ssTreatment = 0.0;
78-
79-
// First check pre-conditions:
8077
if ( !isTypedArrayLike( x ) && !isNumberArray( x ) ) {
81-
throw new TypeError( 'invalid first argument. x must be a numeric array. Value: `' + x + '`.');
78+
throw new TypeError( 'invalid argument. First argument must be a numeric array. Value: `' + x + '`.' );
8279
}
83-
8480
opts = copy( defaults );
85-
86-
// Validate the options:
8781
if ( arguments.length > 2 ) {
8882
err = validate( opts, options );
8983
if ( err ) {
9084
throw err;
9185
}
9286
}
93-
94-
if ( x.length <= 1 ) {
95-
throw new RangeError( 'length of x must be greater than or equal to 2.' );
87+
nobs = x.length;
88+
if ( nobs <= 1 ) {
89+
throw new RangeError( 'invalid argument. First argument must have at least two elements. Value: `' + x + '`.' );
9690
}
97-
98-
// Check if factor is an array
9991
if ( !isArray( factor ) ) {
100-
throw new TypeError( 'factor argument must be an array' );
92+
throw new TypeError( 'invalid input argument. Second argument must be an array. Value: `' + treats + '`' );
10193
}
10294

10395
treats = unique( factor );
104-
if ( treats.length <= 1 ) {
105-
throw new RangeError( 'Second argument must have at least two unique elements' );
96+
nGroups = treats.length;
97+
if ( nGroups <= 1 ) {
98+
throw new RangeError( 'invalid input argument. Second argument must contain at least two unique elements. Value: `' + treats + '`' );
10699
}
107-
108-
// Check if the arrays are of the same length.
109-
if ( x.length !== factor.length ) {
110-
throw new RangeError( 'Arguments must be the same length' );
100+
if ( nobs !== factor.length ) {
101+
throw new RangeError( 'invalid input arguments. Arguments `x` and `factor` must be arrays of the same length' );
111102
}
112103

113-
means = meanTable(x, factor);
114-
115-
// Get the grand mean:
116-
for (i = 0; i < x.length; i++) {
117-
grandMean += x[i];
118-
}
119-
120-
grandMean /= x.length;
104+
sumSqTotal = 0.0;
105+
ssTreatment = 0.0;
106+
means = meanTable( x, factor );
107+
grandMean = mean( x );
121108

122-
// Now get total ss
123-
for ( i = 0; i < x.length; i++ ) {
109+
// Now get total ss:
110+
for ( i = 0; i < nobs; i++ ) {
124111
sq = ( x[i] - grandMean ) * ( x[i] - grandMean );
125112
sumSqTotal += sq;
126113
}
@@ -134,26 +121,22 @@ function anova1( x, factor, options ) {
134121
ssTreatment += means[treatment].sampleSize * sq;
135122
}
136123
}
137-
138-
// SSE = SST - ssTreatment
139124
sumSqError = sumSqTotal - ssTreatment;
140-
141-
// Now get the mean sum squares and mean error:
142-
meanSumSqTreat = ssTreatment / ( treats.length - 1 );
143-
meanSumSqError = sumSqError / ( x.length - treats.length );
125+
meanSumSqTreat = ssTreatment / ( nGroups - 1 );
126+
meanSumSqError = sumSqError / ( nobs - nGroups );
144127

145128
fScore = meanSumSqTreat / meanSumSqError;
146129

147130
// Now get the p-value:
148-
numDf = treats.length - 1;
149-
denDf = x.length - treats.length;
131+
numDf = nGroups - 1;
132+
denDf = nobs - nGroups;
150133
pVal = 1.0 - cdf( fScore, numDf, denDf );
151134

152135
out = {};
153-
setReadOnly( out, 'treatmentDf', treats.length - 1 );
136+
setReadOnly( out, 'treatmentDf', nGroups - 1 );
154137
setReadOnly( out, 'treatmentSS', ssTreatment );
155138
setReadOnly( out, 'treatmentMSS', meanSumSqTreat );
156-
setReadOnly( out, 'errorDf', x.length - treats.length );
139+
setReadOnly( out, 'errorDf', nobs - nGroups );
157140
setReadOnly( out, 'errorSS', sumSqError );
158141
setReadOnly( out, 'errorMSS', meanSumSqError );
159142
setReadOnly( out, 'statistic', fScore );

lib/node_modules/@stdlib/math/stats/anova1/lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
* 'errorMSS': ~23.1667,
4040
* 'statistic': ~0.297,
4141
* 'pValue': ~0.826,
42-
* 'means': { 'control': { 'mean': 5, 'sampleSize: 3, 'SD': ~4.583 },
43-
* 'treatA': { 'mean': ~6.667, 'sampleSize': 3, 'SD': ~4.041 },
44-
* 'treatB': { 'mean': ~8.333, 'sampleSize': 3, 'SD': ~3.512 },
45-
* 'treatC': { 'mean': 8, 'sampleSize': 3, 'SD': ~6.557 }
42+
* 'means': { 'control': { 'mean': 5.0, 'sampleSize: 3.0, 'SD': ~4.583 },
43+
* 'treatA': { 'mean': ~6.667, 'sampleSize': 3.0, 'SD': ~4.041 },
44+
* 'treatB': { 'mean': ~8.333, 'sampleSize': 3.0, 'SD': ~3.512 },
45+
* 'treatC': { 'mean': 8.0, 'sampleSize': 3.0, 'SD': ~6.557 }
4646
* },
4747
* 'method': 'One-Way ANOVA'
4848
* }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
/**
4+
* Computes the arithmetic mean of a numeric array.
5+
*
6+
* @param {NumericArray} arr - input array
7+
* @returns {number} arithmetic mean
8+
*/
9+
function mean( arr ) {
10+
var delta;
11+
var len;
12+
var mu;
13+
var i;
14+
15+
mu = 0;
16+
len = arr.length;
17+
for ( i = 0; i < len; i++ ) {
18+
delta = arr[ i ] - mu;
19+
mu += delta / (i+1);
20+
}
21+
return mu;
22+
}
23+
24+
25+
// EXPORTS //
26+
27+
module.exports = mean;

lib/node_modules/@stdlib/math/stats/chi2gof/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
var chi2gof = require( '@stdlib/math/stats/chi2gof' );
3131
```
3232

33-
### chi2gof( x, y\[, ...params]\[, opts] )
33+
#### chi2gof( x, y\[, ...params]\[, opts] )
3434

3535
For an [array][mdn-array] or [typed array][mdn-typed-array] of integers `x`, a chi-square goodness-of-fit is computed for the null hypothesis that the values of `x` come from the discrete distribution specified by `y`. `y` can be an `array` of expected frequencies, an `array` of population probabilities that sum to one, or a string with the name of the discrete distribution to test against. In the latter case, the parameters of the distribution must be supplied as additional arguments after `y`. The function returns an object holding the calculated test statistic, the p-value of the test, as well as the test decision.
3636

lib/node_modules/@stdlib/math/stats/chi2gof/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Test decision.
7474

7575
out.pValue: number
76-
P-value of the test.
76+
p-value of the test.
7777

7878
out.statistic: number
7979
Value of test statistic.

0 commit comments

Comments
 (0)