1 | ## Vector Functionality
|
2 |
|
3 | ### sum()
|
4 |
|
5 | **sum( array )**
|
6 |
|
7 | Returns the sum of the `array` vector.
|
8 |
|
9 | jStat.sum([1,2,3]) === 6
|
10 |
|
11 | **fn.sum( [bool][, callback] )**
|
12 |
|
13 | Returns the sum of a vector or matrix columns.
|
14 |
|
15 | jStat( 1, 5, 5 ).sum() === 15
|
16 | jStat([[1,2],[3,4]]).sum() === [ 4, 6 ]
|
17 |
|
18 | If callback is passed then will pass result as first argument.
|
19 |
|
20 | jStat( 1, 5, 5 ).sum(function( result ) {
|
21 | // result === 15
|
22 | });
|
23 |
|
24 | If pass boolean true as first argument, then return sum of entire matrix.
|
25 |
|
26 | jStat([[1,2],[3,4]]).sum( true ) === 10
|
27 |
|
28 | And the two can be combined.
|
29 |
|
30 | jStat([[1,2],[3,4]]).sum(true, function( result ) {
|
31 | // result === 10
|
32 | });
|
33 |
|
34 | ### sumsqrd()
|
35 |
|
36 | **sumsqrd( array )**
|
37 |
|
38 | Returns the sum squared of the `array` vector.
|
39 |
|
40 | jStat.sumsqrd([1,2,3]) === 14
|
41 |
|
42 | **fn.sumsqrd( [bool][, callback] )**
|
43 |
|
44 | Returns the sum squared of a vector or matrix columns.
|
45 |
|
46 | jStat( 1, 5, 5 ).sumsqrd() === 55
|
47 | jStat([[1,2],[3,4]]).sumsqrd() === [ 10, 20 ]
|
48 |
|
49 | If callback is passed then will pass result as first argument.
|
50 |
|
51 | jStat( 1, 5, 5 ).sumsqrd(function( result ) {
|
52 | // result === 55
|
53 | });
|
54 |
|
55 | If pass boolean true as first argument, then return sum squared of entire matrix.
|
56 |
|
57 | jStat([[1,2],[3,4]]).sumsqrd( true ) === 650
|
58 |
|
59 | And the two can be combined.
|
60 |
|
61 | jStat([[1,2],[3,4]]).sumsqrd(true,function( result ) {
|
62 | // result === 650
|
63 | });
|
64 |
|
65 | ### sumsqerr()
|
66 |
|
67 | **sumsqerr( array )**
|
68 |
|
69 | Returns the sum of squared errors of prediction of the `array` vector.
|
70 |
|
71 | jStat.sumsqerr([1,2,3]) === 2
|
72 |
|
73 | **fn.sumsqerr( [bool][, callback] )**
|
74 |
|
75 | Returns the sum of squared errors of prediction of a vector or matrix columns.
|
76 |
|
77 | jStat( 1, 5, 5 ).sumsqerr() === 10
|
78 | jStat([[1,2],[3,4]]).sumsqerr() === [ 2, 2 ]
|
79 |
|
80 | If callback is passed then will pass result as first argument.
|
81 |
|
82 | jStat( 1, 5, 5 ).sumsqerr(function( result ) {
|
83 | // result === 55
|
84 | });
|
85 |
|
86 | If pass boolean true as first argument, then return sum of squared errors of entire matrix.
|
87 |
|
88 | jStat([[1,2],[3,4]]).sumsqerr( true ) === 0
|
89 |
|
90 | And the two can be combined.
|
91 |
|
92 | jStat([[1,2],[3,4]]).sumsqerr(true,function( result ) {
|
93 | // result === 0
|
94 | });
|
95 |
|
96 | ### sumrow()
|
97 |
|
98 | **sumrow( array )**
|
99 |
|
100 | Returns the sum of the `array` vector in row-based order.
|
101 |
|
102 | jStat.sumrow([1,2,3]) === 6
|
103 |
|
104 | **fn.sumrow( [bool][, callback] )**
|
105 |
|
106 | Returns the sum of a vector or matrix rows.
|
107 |
|
108 | jStat( 1, 5, 5 ).sumrow() === 15
|
109 | jStat([[1,2],[3,4]]).sumrow() === [ 3, 7 ]
|
110 |
|
111 | If callback is passed then will pass result as first argument.
|
112 |
|
113 | jStat( 1, 5, 5 ).sumrow(function( result ) {
|
114 | // result === 15
|
115 | });
|
116 |
|
117 | If pass boolean true as first argument, then return sum of entire matrix.
|
118 |
|
119 | jStat([[1,2],[3,4]]).sumrow( true ) === 10
|
120 |
|
121 | And the two can be combined.
|
122 |
|
123 | jStat([[1,2],[3,4]]).sumrow(true,function( result ) {
|
124 | // result === 10
|
125 | });
|
126 |
|
127 |
|
128 | ### product()
|
129 |
|
130 | **product( array )**
|
131 |
|
132 | Returns the product of the `array` vector.
|
133 |
|
134 | jStat.product([1,2,3]) === 6
|
135 |
|
136 | **fn.product( [bool][, callback] )**
|
137 |
|
138 | Returns the product of a vector or matrix columns.
|
139 |
|
140 | jStat( 1, 5, 5 ).product() === 120
|
141 | jStat([[1,2],[3,4]]).product() === [ 3, 8 ]
|
142 |
|
143 | If callback is passed then will pass result as first argument.
|
144 |
|
145 | jStat( 1, 5, 5 ).product(function( result ) {
|
146 | // result === 120
|
147 | });
|
148 |
|
149 | If pass boolean true as first argument, then return sumsqerr of entire matrix.
|
150 |
|
151 | jStat([[1,2],[3,4]]).product( true ) === 24
|
152 |
|
153 | And the two can be combined.
|
154 |
|
155 | jStat([[1,2],[3,4]]).product(true,function( result ) {
|
156 | // result === 24
|
157 | });
|
158 |
|
159 | ### min()
|
160 |
|
161 | **min( array )**
|
162 |
|
163 | Returns the minimum value of the `array` vector.
|
164 |
|
165 | jStat.min([1,2,3]) === 1
|
166 |
|
167 | **fn.min( [bool][, callback] )**
|
168 |
|
169 | Returns the minimum value of a vector or matrix columns.
|
170 |
|
171 | jStat( 1, 5, 5 ).min() === 1
|
172 | jStat([[1,2],[3,4]]).min() === [ 1, 2 ]
|
173 |
|
174 | If callback is passed then will pass result as first argument.
|
175 |
|
176 | jStat( 1, 5, 5 ).min(function( result ) {
|
177 | // result === 1
|
178 | });
|
179 |
|
180 | If pass boolean true as first argument, then return minimum of entire matrix.
|
181 |
|
182 | jStat([[1,2],[3,4]]).min( true ) === 1
|
183 |
|
184 | And the two can be combined.
|
185 |
|
186 | jStat([[1,2],[3,4]]).min(true,function( result ) {
|
187 | // result === 1
|
188 | });
|
189 |
|
190 | ### max()
|
191 |
|
192 | **max( array )**
|
193 |
|
194 | Returns the maximum value of the `array` vector.
|
195 |
|
196 | jStat.max([1,2,3]) === 3
|
197 |
|
198 | **fn.max( [bool][, callback] )**
|
199 |
|
200 | Returns the maximum value of a vector or matrix columns.
|
201 |
|
202 | jStat( 1, 5, 5 ).max() === 5
|
203 | jStat([[1,2],[3,4]]).max() === [ 3, 4 ]
|
204 |
|
205 | If callback is passed then will pass result as first argument.
|
206 |
|
207 | jStat( 1, 5, 5 ).max(function( result ) {
|
208 | // result === 5
|
209 | });
|
210 |
|
211 | If pass boolean true as first argument, then return maximum of entire matrix.
|
212 |
|
213 | jStat([[1,2],[3,4]]).max( true ) === 4
|
214 |
|
215 | And the two can be combined.
|
216 |
|
217 | jStat([[1,2],[3,4]]).max(true,function( result ) {
|
218 | // result === 4
|
219 | });
|
220 |
|
221 | ### mean()
|
222 |
|
223 | **mean( array )**
|
224 |
|
225 | Returns the mean of the `array` vector.
|
226 |
|
227 | jStat.mean([1,2,3]) === 2
|
228 |
|
229 | **fn.max( [bool,][callback] )**
|
230 |
|
231 | Returns the mean of a vector or matrix columns.
|
232 |
|
233 | jStat( 1, 5, 5 ).mean() === 3
|
234 | jStat([[1,2],[3,4]]).mean() === [ 2, 3 ]
|
235 |
|
236 | If callback is passed then will pass result as first argument.
|
237 |
|
238 | jStat( 1, 5, 5 ).mean(function( result ) {
|
239 | // result === 3
|
240 | });
|
241 |
|
242 | If pass boolean true as first argument, then return mean of entire matrix.
|
243 |
|
244 | jStat([[1,2],[3,4]]).mean( true ) === 2.5
|
245 |
|
246 | And the two can be combined.
|
247 |
|
248 | jStat([[1,2],[3,4]]).mean(true,function( result ) {
|
249 | // result === 2.5
|
250 | });
|
251 |
|
252 | ### meansqerr()
|
253 |
|
254 | **meansqerr( array )**
|
255 |
|
256 | Returns the mean squared error of the `array` vector.
|
257 |
|
258 | jStat.meansqerr([1,2,3]) === 0.66666...
|
259 |
|
260 | **fn.meansqerr( [bool][, callback] )**
|
261 |
|
262 | Returns the mean squared error of a vector or matrix columns.
|
263 |
|
264 | jStat( 1, 5, 5 ).meansqerr() === 2
|
265 | jStat([[1,2],[3,4]]).meansqerr() === [ 1, 1 ]
|
266 |
|
267 | If callback is passed then will pass result as first argument.
|
268 |
|
269 | jStat( 1, 5, 5 ).meansqerr(function( result ) {
|
270 | // result === 2
|
271 | });
|
272 |
|
273 | If pass boolean true as first argument, then return mean squared error of entire matrix.
|
274 |
|
275 | jStat([[1,2],[3,4]]).meansqerr( true ) === 0
|
276 |
|
277 | And the two can be combined.
|
278 |
|
279 | jStat([[1,2],[3,4]]).meansqerr(true,function( result ) {
|
280 | // result === 0
|
281 | });
|
282 |
|
283 | ### geomean()
|
284 |
|
285 | **geomean( array )**
|
286 |
|
287 | Returns the geometric mean of the `array` vector.
|
288 |
|
289 | jStat.geomean([4,1,1/32]) === 0.5
|
290 |
|
291 | **fn.geomean( [bool][, callback] )**
|
292 |
|
293 | Returns the geometric mean of a vector or matrix columns.
|
294 |
|
295 | jStat([4,1,1\32]).geomean() === 0.5
|
296 | jStat([[1,2],[3,4]]).geomean() === [ 1.732..., 2.828... ]
|
297 |
|
298 | If callback is passed then will pass result as first argument.
|
299 |
|
300 | jStat([4,1,1\32]).geomean(function( result ) {
|
301 | // result === 0.5
|
302 | });
|
303 |
|
304 | If pass boolean true as first argument, then return geometric mean of entire matrix.
|
305 |
|
306 | jStat([[1,2],[3,4]]).geomean( true ) === 2.213...
|
307 |
|
308 | And the two can be combined.
|
309 |
|
310 | jStat([[1,2],[3,4]]).geomean(true,function( result ) {
|
311 | // result === 2.213...
|
312 | });
|
313 |
|
314 | ### median()
|
315 |
|
316 | **median( array )**
|
317 |
|
318 | Returns the median of the `array` vector.
|
319 |
|
320 | jStat.median([1,2,3]) === 2
|
321 |
|
322 | **fn.median( [bool][, callback] )**
|
323 |
|
324 | Returns the median of a vector or matrix columns.
|
325 |
|
326 | jStat( 1, 5, 5 ).median() === 3
|
327 | jStat([[1,2],[3,4]]).median() === [ 2, 3 ]
|
328 |
|
329 | If callback is passed then will pass result as first argument.
|
330 |
|
331 | jStat( 1, 5, 5 ).median(function( result ) {
|
332 | // result === 3
|
333 | });
|
334 |
|
335 | If pass boolean true as first argument, then return median of entire matrix.
|
336 |
|
337 | jStat([[1,2],[3,4]]).median( true ) === 2.5
|
338 |
|
339 | And the two can be combined.
|
340 |
|
341 | jStat([[1,2],[3,4]]).median(true,function( result ) {
|
342 | // result === 2.5
|
343 | });
|
344 |
|
345 | ### cumsum()
|
346 |
|
347 | **cumsum( array )**
|
348 |
|
349 | Returns an array of partial sums in the sequence.
|
350 |
|
351 | jStat.cumsum([1,2,3]) === [1,3,6]
|
352 |
|
353 | **fn.cumsum( [bool][, callback] )**
|
354 |
|
355 | Returns an array of partial sums for a vector or matrix columns.
|
356 |
|
357 | jStat( 1, 5, 5 ).cumsum() === [1,3,6,10,15]
|
358 | jStat([[1,2],[3,4]]).cumsum() === [[1,4],[2,6]]
|
359 |
|
360 | If callback is passed then will pass result as first argument.
|
361 |
|
362 | jStat( 1, 5, 5 ).cumsum(function( result ) {
|
363 | // result === [1,3,6,10,15]
|
364 | });
|
365 |
|
366 | If pass boolean true as first argument, then return cumulative sums of the matrix.
|
367 |
|
368 | jStat([[1,2],[3,4]]).cumsum( true ) === [[1,3],[3,7]]
|
369 |
|
370 | And the two can be combined.
|
371 |
|
372 | jStat([[1,2],[3,4]]).cumsum(true,function( result ) {
|
373 | // result === ...
|
374 | });
|
375 |
|
376 | ### cumprod()
|
377 |
|
378 | **cumprod( array )**
|
379 |
|
380 | Returns an array of partial products in the sequence.
|
381 |
|
382 | jStat.cumprod([2,3,4]) === [2,6,24]
|
383 |
|
384 | **fn.cumprod( [bool][, callback] )**
|
385 |
|
386 | Returns an array of partial products for a vector or matrix columns.
|
387 |
|
388 | jStat( 1, 5, 5 ).cumprod() === [1,2,6,24,120]
|
389 | jStat([[1,2],[3,4]]).cumprod() === [[1,3],[2,8]]
|
390 |
|
391 | If callback is passed then will pass result as first argument.
|
392 |
|
393 | jStat( 1, 5, 5 ).cumprod(function( result ) {
|
394 | // result === [1,2,6,24,120]
|
395 | });
|
396 |
|
397 | If pass boolean true as first argument, then return cumulative products of the matrix.
|
398 |
|
399 | jStat([[1,2],[3,4]]).cumprod( true ) === [[1,2],[3,12]]
|
400 |
|
401 | And the two can be combined.
|
402 |
|
403 | jStat([[1,2],[3,4]]).cumprod(true,function( result ) {
|
404 | // result === ...
|
405 | });
|
406 |
|
407 | ### diff()
|
408 |
|
409 | **diff( array )**
|
410 |
|
411 | Returns an array of the successive differences of the array.
|
412 |
|
413 | jStat.diff([1,2,2,3]) === [1,0,1]
|
414 |
|
415 | **fn.diff( [bool][, callback] )**
|
416 |
|
417 | Returns an array of successive differences for a vector or matrix columns.
|
418 |
|
419 | jStat([1,2,2,3]).diff() === [1,0,1]
|
420 | jStat([[1,2],[3,4],[1,4]]).diff() === [[2,-2],[2,0]]
|
421 |
|
422 | If callback is passed then will pass result as first argument.
|
423 |
|
424 | jStat([[1,2],[3,4],[1,4]]).diff(function( result ) {
|
425 | // result === [[2,-2],[2,0]]
|
426 | });
|
427 |
|
428 | If pass boolean true as first argument, then return successive difference for the whole matrix.
|
429 |
|
430 | jStat([[1,2],[3,4],[1,4]]).diff(true) === [0,2]
|
431 |
|
432 | And the two can be combined.
|
433 |
|
434 | jStat([[1,2],[3,4],[1,4]]).diff(true,function( result ) {
|
435 | // result === [0,2]
|
436 | });
|
437 |
|
438 | ### rank()
|
439 |
|
440 | **rank( array )**
|
441 |
|
442 | Returns an array of the ranks of the array.
|
443 |
|
444 | jStat.rank([1, 2, 2, 3]) === [1, 2.5, 2.5, 4]
|
445 |
|
446 | **fn.rank( [bool][, callback] )**
|
447 |
|
448 | Returns an array of ranks for a vector or matrix columns.
|
449 |
|
450 | jStat([1, 2, 2, 3]).rank() === [1, 2.5, 2.5, 4]
|
451 | jStat([[1, 2], [3, 4], [1, 4]]).rank() === [[1.5, 3, 1.5], [1, 2.5, 2.5]]
|
452 |
|
453 | If callback is passed then will pass result as first argument.
|
454 |
|
455 | jStat([[1, 2], [3, 4], [1, 4]]).rank(function( result ) {
|
456 | // result === [[1.5, 3, 1.5], [1, 2.5, 2.5]]
|
457 | });
|
458 |
|
459 | If pass boolean true as first argument, then return rank for the whole matrix.
|
460 |
|
461 | jStat([[1, 2], [3, 4], [1, 4]]).rank(true) === [2, 5, 2, 5, 2, 5]
|
462 |
|
463 | And the two can be combined.
|
464 |
|
465 | jStat([[1, 2], [3, 4], [1, 4]]).rank(true, function( result ) {
|
466 | // result === [2, 5, 2, 5, 2, 5]
|
467 | });
|
468 |
|
469 | ### mode()
|
470 |
|
471 | **mode( array )**
|
472 |
|
473 | Returns the mode of the `array` vector.
|
474 | If there are multiple modes then `mode()` will return all of them.
|
475 |
|
476 | jStat.mode([1,2,2,3]) === 2
|
477 | jStat.mode([1,2,3]) === [1,2,3]
|
478 |
|
479 | **fn.mode( [bool][, callback] )**
|
480 |
|
481 | Returns the mode for a vector or matrix columns.
|
482 |
|
483 | jStat([1,2,2,3]).mode() === 2
|
484 | jStat([[1,2],[3,4],[1,4]]).mode() === [1,4]
|
485 |
|
486 | If callback is passed then will pass result as first argument.
|
487 |
|
488 | jStat( 1, 5, 5 ).mode(function( result ) {
|
489 | // result === false
|
490 | });
|
491 |
|
492 | If pass boolean true as first argument, then the matrix will be treated as one
|
493 | dimensional.
|
494 |
|
495 | jStat([[5,4],[5, 2], [5,2]]).mode( true ) === 5
|
496 |
|
497 | ### range()
|
498 |
|
499 | **range( array )**
|
500 |
|
501 | Returns the range of the `array` vector.
|
502 |
|
503 | jStat.range([1,2,3]) === 2
|
504 |
|
505 | **fn.range( [bool][, callback] )**
|
506 |
|
507 | Returns the range for a vector or matrix columns.
|
508 |
|
509 | jStat([1,2,3]).range() === 2
|
510 | jStat([[1,2],[3,4]]).range() === [2,2]
|
511 |
|
512 | If callback is passed then will pass result as first argument.
|
513 |
|
514 | jStat( 1, 5, 5 ).range(function( result ) {
|
515 | // result === 4
|
516 | });
|
517 |
|
518 | If pass boolean true as first argument, then return range of the matrix.
|
519 |
|
520 | jStat([[1,2],[3,5]]).range( true ) === true
|
521 |
|
522 | And the two can be combined.
|
523 |
|
524 | jStat([[1,2],[3,5]]).range(true,function( result ) {
|
525 | // result === 1
|
526 | });
|
527 |
|
528 | ### variance()
|
529 |
|
530 | **variance( array[, flag] )**
|
531 |
|
532 | Returns the variance of the `array` vector.
|
533 | By default, the population variance is calculated.
|
534 | Passing `true` to `flag` indicates to compute the sample variance instead.
|
535 |
|
536 | jStat.variance([1,2,3,4]) === 1.25
|
537 | jStat.variance([1,2,3,4],true) === 1.66666...
|
538 |
|
539 | **fn.variance( [bool][, callback] )**
|
540 |
|
541 | Returns the variance for a vector or matrix columns.
|
542 |
|
543 | **Note:** Cannot pass flag to indicate between population or sample for matrices.
|
544 | There is a feature request for this on [Issue #51](https://github.com/jstat/jstat/issues/51).
|
545 |
|
546 | jStat([1,2,3,4]).variance() === 1.25
|
547 | jStat([[1,2],[3,4]]).variance() === [1,1]
|
548 |
|
549 | If callback is passed then will pass result as first argument.
|
550 |
|
551 | jStat( 1, 5, 5 ).variance(function( result ) {
|
552 | // result === 2
|
553 | });
|
554 |
|
555 | If pass boolean true as first argument, then return variance of the matrix.
|
556 |
|
557 | jStat([[1,2],[3,5]]).variance( true ) === 0.140625
|
558 |
|
559 | And the two can be combined.
|
560 |
|
561 | jStat([[1,2],[3,5]]).variance(true,function( result ) {
|
562 | // result === 0.140625
|
563 | });
|
564 |
|
565 | ### pooledvariance()
|
566 |
|
567 | **pooledvariance( arrays )**
|
568 |
|
569 | Returns the pooled (sample) variance of an array of vectors.
|
570 | Assumes the population variance of the vectors are the same.
|
571 |
|
572 | jStat.pooledvariance([[1,2],[3,4]]) === 0.5
|
573 |
|
574 | ### deviation()
|
575 |
|
576 | **deviation( array )**
|
577 |
|
578 | Returns the deviation of the `array` vector.
|
579 |
|
580 | jStat.deviation([1,2,3,4]) === [-1.5, -0.5, 0.5, 1.5]
|
581 |
|
582 | **fn.deviation( [bool][, callback] )**
|
583 |
|
584 | Returns the deviation for a vector or matrix columns.
|
585 |
|
586 | jStat([1,2,3,4]).deviation() === [-1.5, -0.5, 0.5, 1.5]
|
587 | jStat([[1,2],[3,4]]).deviation() === [[-1,1],[-1,1]]
|
588 |
|
589 | If callback is passed then will pass result as first argument.
|
590 |
|
591 | jStat( 1, 4, 4 ).deviation(function( result ) {
|
592 | // result === [-1.5, -0.5, 0.5, 1.5]
|
593 | });
|
594 |
|
595 | If pass boolean true as first argument, then return variance of the matrix.
|
596 |
|
597 | jStat([[1,2],[3,5]]).deviation( true ) === [-0.5, 0.5, -1, 1]
|
598 |
|
599 | And the two can be combined.
|
600 |
|
601 | jStat([[1,2],[3,5]]).deviation(true,function( result ) {
|
602 | // result === [-0.5, 0.5, -1, 1]
|
603 | });
|
604 |
|
605 | ### stdev()
|
606 |
|
607 | **stdev( array[, flag] )**
|
608 |
|
609 | Returns the standard deviation of the `array` vector.
|
610 | By default, the population standard deviation is returned.
|
611 | Passing `true` to `flag` returns the sample standard deviation.
|
612 |
|
613 | The 'sample' standard deviation is also called the 'corrected standard deviation', and is an unbiased estimator of the population standard deviation.
|
614 | The population standard deviation is also the 'uncorrected standard deviation', and is a biased but minimum-mean-squared-error estimator.
|
615 |
|
616 | jStat.stdev([1,2,3,4]) === 1.118...
|
617 | jStat.stdev([1,2,3,4],true) === 1.290...
|
618 |
|
619 | **fn.stdev( [bool][, callback] )**
|
620 |
|
621 | Returns the standard deviation for a vector or matrix columns.
|
622 |
|
623 | **Note:** Cannot pass `flag` to indicate between population or sample for matrices.
|
624 | There is a feature request for this on [Issue #51](https://github.com/jstat/jstat/issues/51).
|
625 |
|
626 | jStat([1,2,3,4]).stdev() === 1.118...
|
627 | jStat([1,2,3,4]).stdev(true) === 1.290...
|
628 | jStat([[1,2],[3,4]]).stdev() === [1,1]
|
629 |
|
630 | If callback is passed then will pass result as first argument.
|
631 |
|
632 | jStat( 1, 4, 4 ).stdev(function( result ) {
|
633 | // result === 1.118...
|
634 | });
|
635 | jStat( 1, 4, 4 ).stdev(true,function( result ) {
|
636 | // result === 1.290...
|
637 | });
|
638 |
|
639 | If pass boolean true as first argument, then return variance of the matrix.
|
640 |
|
641 | jStat([[1,2],[3,5]]).stdev( true ) === 0.25
|
642 |
|
643 | And the two can be combined.
|
644 |
|
645 | jStat([[1,2],[3,5]]).stdev(true,function( result ) {
|
646 | // result === 0.25
|
647 | });
|
648 |
|
649 | ### pooledstdev()
|
650 |
|
651 | **pooledstdev( arrays )**
|
652 |
|
653 | Returns the pooled (sample) standard deviation of an array of vectors.
|
654 | Assumes the population standard deviation of the vectors are the same.
|
655 |
|
656 | jStat.pooledstdev([[1,2],[3,4]]) === 0.707...
|
657 |
|
658 | ### meandev()
|
659 |
|
660 | **meandev( array )**
|
661 |
|
662 | Returns the mean absolute deviation of the `array` vector.
|
663 |
|
664 | jStat.meandev([1,2,3,4]) === 1
|
665 |
|
666 | **fn.meandev( [bool][, callback] )**
|
667 |
|
668 | Returns the mean absolute deviation for a vector or matrix columns.
|
669 |
|
670 | jStat([1,2,3,4]).meandev() === 1
|
671 | jStat([[1,2],[3,4]]).meandev() === [1,1]
|
672 |
|
673 | If callback is passed then will pass result as first argument.
|
674 |
|
675 | jStat( 1, 4, 4 ).meandev(function( result ) {
|
676 | // result === 1
|
677 | });
|
678 |
|
679 | If pass boolean true as first argument, then return mean absolute deviation of the matrix.
|
680 |
|
681 | jStat([[1,2],[3,5]]).meandev( true ) === 0.25
|
682 |
|
683 | And the two can be combined.
|
684 |
|
685 | jStat([[1,2],[3,5]]).meandev(true,function( result ) {
|
686 | // result === 0.25
|
687 | });
|
688 |
|
689 | ### meddev()
|
690 |
|
691 | **meddev( array )**
|
692 |
|
693 | Returns the median absolute deviation of the `array` vector.
|
694 |
|
695 | jStat.meddev([1,2,3,4]) === 1
|
696 |
|
697 | **fn.meddev( [bool][, callback] )**
|
698 |
|
699 | Returns the median absolute deviation for a vector or matrix columns.
|
700 |
|
701 | jStat([1,2,3,4]).meddev() === 1
|
702 | jStat([[1,2],[3,4]]).meddev() === [1,1]
|
703 |
|
704 | If callback is passed then will pass result as first argument.
|
705 |
|
706 | jStat( 1, 4, 4 ).meddev(function( result ) {
|
707 | // result === 1
|
708 | });
|
709 |
|
710 | If pass boolean true as first argument, then return median absolute deviation of the matrix.
|
711 |
|
712 | jStat([[1,2],[3,5]]).meddev( true ) === 0.25
|
713 |
|
714 | And the two can be combined.
|
715 |
|
716 | jStat([[1,2],[3,5]]).meddev(true,function( result ) {
|
717 | // result === 0.25
|
718 | });
|
719 |
|
720 | ### skewness()
|
721 |
|
722 | **skewness( array )**
|
723 |
|
724 | Returns the skewness of the `array` vector (third standardized moment).
|
725 |
|
726 | jStat.skewness([1,2,2,3,5]) === 0.75003...
|
727 |
|
728 | ### kurtosis()
|
729 |
|
730 | **kurtosis( array )**
|
731 |
|
732 | Returns the excess kurtosis of the `array` vector (fourth standardized moment - 3).
|
733 |
|
734 | jStat.kurtosis([1,2,3,4]) === -0.63610...
|
735 |
|
736 | ### coeffvar()
|
737 |
|
738 | **coeffvar( array )**
|
739 |
|
740 | Returns the coefficient of variation of the `array` vector.
|
741 |
|
742 | jStat.coeffvar([1,2,3,4]) === 0.447...
|
743 |
|
744 | **fn.coeffvar( [bool][, callback] )**
|
745 |
|
746 | Returns the coefficient of variation for a vector or matrix columns.
|
747 |
|
748 | jStat([1,2,3,4]).coeffvar() === 0.447...
|
749 | jStat([[1,2],[3,4]]).coeffvar() === [0.5,0.333...]
|
750 |
|
751 | If callback is passed then will pass result as first argument.
|
752 |
|
753 | jStat( 1, 4, 4 ).coeffvar(function( result ) {
|
754 | // result === 0.447...
|
755 | });
|
756 |
|
757 | If pass boolean true as first argument, then return coefficient of variation of the matrix.
|
758 |
|
759 | jStat([[1,2],[3,5]]).coeffvar( true ) === 0.142...
|
760 |
|
761 | And the two can be combined.
|
762 |
|
763 | jStat([[1,2],[3,5]]).coeffvar(true,function( result ) {
|
764 | // result === 0.142...
|
765 | });
|
766 |
|
767 | ### quartiles()
|
768 |
|
769 | **quartiles( array )**
|
770 |
|
771 | Returns the quartiles of the `array` vector.
|
772 |
|
773 | jStat.quartiles( jStat.seq(1,100,100)) === [25,50,75]
|
774 |
|
775 | **fn.quartiles( [callback] )**
|
776 |
|
777 | Returns the quartiles for a vector or matrix columns.
|
778 |
|
779 | jStat(1,100,100).quartiles() === [25,50,75]
|
780 | jStat(1,100,100,function( x ) {
|
781 | return [x,x];
|
782 | }).quartiles() === [[25,50,75],[25,50,75]]
|
783 |
|
784 | If callback is passed then will pass result as first argument.
|
785 |
|
786 | jStat(1,100,100).quartiles(function( result ) {
|
787 | // result === [25,50,75]
|
788 | });
|
789 |
|
790 | ### quantiles()
|
791 |
|
792 | **quantiles( dataArray, quantilesArray[, alphap[, betap]] )**
|
793 |
|
794 | Like quartiles, but calculate and return arbitrary quantiles of the `dataArray` vector
|
795 | or matrix (column-by-column).
|
796 |
|
797 | jStat.quantiles([1, 2, 3, 4, 5, 6],
|
798 | [0.25, 0.5, 0.75]) === [1.9375, 3.5, 5.0625]
|
799 |
|
800 | Optional parameters alphap and betap govern the quantile estimation method.
|
801 | For more details see the Wikipedia page on quantiles or scipy.stats.mstats.mquantiles
|
802 | documentation.
|
803 |
|
804 | ### percentile()
|
805 |
|
806 | **percentile( dataArray, k, [exclusive] )**
|
807 |
|
808 | Returns the k-th percentile of values in the `dataArray` range, where k is in the range 0..1, exclusive.
|
809 | Passing true for the exclusive parameter excludes both endpoints of the range.
|
810 |
|
811 | jStat.percentile([1, 2, 3, 4], 0.3) === 1.9;
|
812 | jStat.percentile([1, 2, 3, 4], 0.3, true) === 1.5;
|
813 |
|
814 | ### percentileOfScore()
|
815 |
|
816 | **percentileOfScore( dataArray, score[, kind] )**
|
817 |
|
818 | The percentile rank of score in a given array. Returns the percentage
|
819 | of all values in `dataArray` that are less than (if `kind == 'strict'`) or
|
820 | less or equal than (if `kind == 'weak'`) score. Default is `'weak'`.
|
821 |
|
822 | jStat.percentileOfScore([1, 2, 3, 4, 5, 6], 3), 0.5, 'weak') === 0.5;
|
823 |
|
824 | ### histogram()
|
825 |
|
826 | **histogram( dataArray[, numBins] )**
|
827 |
|
828 | The histogram data defined as the number of `dataArray` elements found in
|
829 | equally sized bins across the range of `dataArray`. Default number
|
830 | of bins is 4.
|
831 |
|
832 | jStat.histogram([100, 101, 102, 230, 304, 305, 400], 3) === [3, 1, 3];
|
833 |
|
834 | ### covariance()
|
835 |
|
836 | **covariance( array1, array2 )**
|
837 |
|
838 | Returns the covariance of the `array1` and `array2` vectors.
|
839 |
|
840 | var seq = jStat.seq( 0, 10, 11 );
|
841 | jStat.covariance( seq, seq ) === 11;
|
842 |
|
843 | ### corrcoeff()
|
844 |
|
845 | **corrcoeff( array1, array2 )**
|
846 |
|
847 | Returns the population correlation coefficient of the `array1` and `array2` vectors (Pearson's Rho).
|
848 |
|
849 | var seq = jStat.seq( 0, 10, 11 );
|
850 | jStat.corrcoeff( seq, seq ) === 1;
|
851 |
|
852 |
|
853 | **spearmancoeff( array1, array2 )**
|
854 |
|
855 | Returns the rank correlation coefficient of the `array1` and `array2` vectors (Spearman's Rho).
|
856 |
|
857 | jStat.spearmancoeff([1, 2, 3, 4], [5, 6, 9, 7]) == 0.8;
|
858 | jStat.spearmancoeff([1, 2, 2, 4], [5, 2, 5, 7]) == 0.5;
|