-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statistic Module added #243
Changes from 3 commits
d7d95a2
adcd925
063e7bd
f637c05
bdd4339
2239320
2a76ba2
c3aea80
72a910b
acc73da
a2c97bf
d83d48b
009a8cd
b130a04
9962331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,151 @@ | ||||||||||||||
### statistics | ||||||||||||||
|
||||||||||||||
> Statisctics Functions. <a href="docs/underscore.collections.statistics.js.html" class="btn btn-primary btn-xs">View Annotated Source</a> | ||||||||||||||
|
||||||||||||||
#### mean | ||||||||||||||
|
||||||||||||||
Signature: `_.mean(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.mean` function finds out the average value from the array of numbers. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.mean([]); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.mean([0, 1, 2, 3, 4]); | ||||||||||||||
//=> 2 | ||||||||||||||
|
||||||||||||||
_.mean(null) | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### median | ||||||||||||||
|
||||||||||||||
Signature: `_.median(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.median` function finds out the middle value from the array of numbers. | ||||||||||||||
|
||||||||||||||
Calulation of median is done using the following method. | ||||||||||||||
|
||||||||||||||
If the array has odd numbers then median is the middle element. | ||||||||||||||
|
||||||||||||||
If the array has even numbers then average of middle two numbers is the median value. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Odd/even number of numbers. For brevity and less confusion, though, I suggest "length".
Suggested change
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.median([]); | ||||||||||||||
//=> undefined | ||||||||||||||
|
||||||||||||||
_.median([1, 2, 3]); | ||||||||||||||
//=> 2 | ||||||||||||||
|
||||||||||||||
_.median([1, 2, 3, 4]) | ||||||||||||||
// => 2.5 | ||||||||||||||
|
||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### sum | ||||||||||||||
|
||||||||||||||
Signature: `_.sum(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.sum` function calculates the sum of the given arrays. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I presume it sums a single array.
Suggested change
|
||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.sum([]); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.sum([0, 1, 2, 3, 4]); | ||||||||||||||
//=> 10 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### variance | ||||||||||||||
|
||||||||||||||
Signature: `_.variance(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.variance` function return the variance of the numeric elements of the collection. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a link here to the Wikipedia entry that explains the variance. Likewise for the other statistical concepts that follow. |
||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.variance([]); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.variance([0, 1, 2, 3, 4]); | ||||||||||||||
//=> 1.25 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### standardDeviation | ||||||||||||||
|
||||||||||||||
Signature: `_.standardDeviation(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.standardDeviation` function return the standard deviation of the numeric elements of the collection. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.standardDeviation([]); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.standardDeviation([1, 2, 3, 4]); | ||||||||||||||
//=> 1.118 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### standardError | ||||||||||||||
|
||||||||||||||
Signature: `_.standardError(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.standardError` function return the standard error of the numeric elements of the collection. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.standardError([]); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.standardError([1, 2, 3, 4]); | ||||||||||||||
//=> 0.64 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### mode | ||||||||||||||
|
||||||||||||||
Signature: `_.mode(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.mode` function return the element (or element-based computation) that appears most frequently in the collection. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.mode([]); | ||||||||||||||
//=> undefined | ||||||||||||||
|
||||||||||||||
_.mode([1, 1, 3, 4]); | ||||||||||||||
//=> 1 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### statRange | ||||||||||||||
|
||||||||||||||
Signature: `_.statRange(... arrays:Array ...)` | ||||||||||||||
|
||||||||||||||
The `_.statRange` function return the difference of the max and min value of the elements in the array. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.statRange([]); | ||||||||||||||
//=> -Infinity | ||||||||||||||
|
||||||||||||||
_.statRange([1, 1, 3, 4]); | ||||||||||||||
//=> 3 | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
#### percentile | ||||||||||||||
|
||||||||||||||
Signature: `_.percentile(... arrays:Array ...,percentileval:number)` | ||||||||||||||
|
||||||||||||||
The `_.percentile` function return the percentile value of the numeric elements from the collection like 50th,75th,99th etc. | ||||||||||||||
|
||||||||||||||
```javascript | ||||||||||||||
|
||||||||||||||
_.percentile([], 10); | ||||||||||||||
//=> 0 | ||||||||||||||
|
||||||||||||||
_.percentile([1, 1, 3, 4], 50); | ||||||||||||||
//=> 2 | ||||||||||||||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ export default function variance(collection, iteratee, context) { | |||||
if (typeof iteratee == 'number' && collection != null && typeof collection[0] != 'object') { | ||||||
iteratee = null; | ||||||
} | ||||||
iteratee = cb(iteratee, context); | ||||||
iteratee = iteratee(iteratee, context); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be
Suggested change
|
||||||
|
||||||
var computed = []; | ||||||
var avg = mean(collection, function(value, key, collection) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really
arrays
, plural?