You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-43Lines changed: 79 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# stat-methods
2
2
3
-
[](https://travis-ci.org/boristane/stat-methods.js)[](https://github.com/facebook/jest)[](https://www.codacy.com/app/boris.tane/stat-methods.js?utm_source=github.com&utm_medium=referral&utm_content=boristane/stat-methods.js&utm_campaign=Badge_Grade)[](https://www.npmjs.com/package/stat-methods)
3
+
[](https://travis-ci.org/boristane/stat-methods.js)[](https://github.com/facebook/jest)[](https://www.codacy.com/app/boris.tane/stat-methods.js?utm_source=github.com&utm_medium=referral&utm_content=boristane/stat-methods.js&utm_campaign=Badge_Grade)[](https://www.npmjs.com/package/stat-methods)
4.[Measures of similarity](#Measures-of-similarity)
51
52
52
-
-[covariance](#covariance)
53
-
-[correlation](#correlation)
53
+
-[covariance](#covariance)
54
+
-[correlation](#correlation)
54
55
55
56
5.[Regressions](#Regressions)
56
-
-[linReg](#linReg)
57
+
-[linReg](#linReg)
57
58
58
59
### Averages and measures of central location
59
60
@@ -72,6 +73,7 @@ These methods compute an average or typical value from a population or sample.
72
73
|[midRange](#midRange)| Average of minimum and maximum |
73
74
|[mode](#mode)| Modes (most common data points) of discrete data |
74
75
|[rms](#rms)| Root Mean Square |
76
+
|[percentile](#percentile)| Percentile |
75
77
76
78
Note: The methods do not require the data given to them to be sorted.
77
79
@@ -133,7 +135,7 @@ Return the geometric mean of a numeric data array `arr`.
133
135
The geometric mean is the nth root of the product of the `n` data points (`n` is the number of data points) For example, the geometric mean of three values `a`, `b` and `c` will be equivalent to `(a*b*c) ^ (1/3)`.
134
136
135
137
```js
136
-
geometricMean([4, 1, 1/32]); // -> 0.5
138
+
geometricMean([4, 1, 1/32]); // -> 0.5
137
139
```
138
140
139
141
The geometric mean indicates the central tendency or typical value of a set of numbers and is often used when comparing different items — finding a single "figure of merit" for these items — when each item has multiple properties that have different numeric ranges.
@@ -156,13 +158,13 @@ Return the median (middle value) of a numeric data array `arr`.
156
158
157
159
The median is the value separating the higher half from the lower half of a data sample. The `median` method uses the “mean of middle two” method:
158
160
159
-
-If there is an odd number of numbers, the median is the middle one.
161
+
- If there is an odd number of numbers, the median is the middle one.
160
162
161
163
```js
162
164
median([1, 2, 3, 4, 5]); // -> 3
163
165
```
164
166
165
-
-If there is an even number of observations, then there is no single middle value; the median is then defined as the mean of the two middle values.
167
+
- If there is an even number of observations, then there is no single middle value; the median is then defined as the mean of the two middle values.
166
168
167
169
```js
168
170
median([1, 2, 3, 4, 5, 6]); // -> 3.5
@@ -180,13 +182,13 @@ Return the low median of a data array `arr`. An optional `compareFunction` param
180
182
181
183
The low median is always a member of the data set. The `medianLow` method accepts both numeric and non numeric data arrays.
182
184
183
-
-When the number of observations is odd, the middle value is returned.
185
+
- When the number of observations is odd, the middle value is returned.
184
186
185
187
```js
186
188
medianLow([1, 2, 3, 4, 5]); // -> 3
187
189
```
188
190
189
-
-When the number of observations is even, the smaller of the two middle values is returned.
191
+
- When the number of observations is even, the smaller of the two middle values is returned.
190
192
191
193
```js
192
194
medianLow([1, 2, 3, 4, 5, 6]); // -> 3
@@ -215,13 +217,13 @@ Return the high median of a data array `arr`. An optional `compareFunction` para
215
217
216
218
The high median is always a member of the data set. The `medianHigh` method accepts both numeric and non numeric data arrays.
217
219
218
-
-When the number of observations is odd, the middle value is returned.
220
+
- When the number of observations is odd, the middle value is returned.
219
221
220
222
```js
221
223
medianHigh([1, 2, 3, 4, 5]); // -> 3
222
224
```
223
225
224
-
-When the number of observations is even, the larger of the two middle values is returned.
226
+
- When the number of observations is even, the larger of the two middle values is returned.
225
227
226
228
```js
227
229
medianHigh([1, 2, 3, 4, 5, 6]); // -> 4
@@ -265,14 +267,14 @@ If the data array is empty or contains a non finite `Number`, the method returns
265
267
#### quartiles
266
268
267
269
```js
268
-
quartiles(arr)
270
+
quartiles(arr);
269
271
```
270
272
271
273
Return the quartiles of a numeric data array `arr`.
272
274
273
-
-The first quartile (`Q1`) is defined as the middle number between the smallest number and the median of the data set.
274
-
-The second quartile (`Q2`) is the median of the data.
275
-
-The third quartile (`Q3`) is the middle value between the median and the highest value of the data set.
275
+
- The first quartile (`Q1`) is defined as the middle number between the smallest number and the median of the data set.
276
+
- The second quartile (`Q2`) is the median of the data.
277
+
- The third quartile (`Q3`) is the middle value between the median and the highest value of the data set.
276
278
277
279
```js
278
280
quartiles([2, 2, 3, 4]); // -> [2, 2.5, 3.5]
@@ -282,8 +284,8 @@ The data set if first ordered, from smallest to highest.
282
284
283
285
The median (`Q2`) is used to divide the ordered data set into two halves.
284
286
285
-
-If there are an odd number of data points in the original ordered data set the median is not included in either half.
286
-
-If there are an even number of data points in the original ordered data set, the sata set is split exactly in half.
287
+
- If there are an odd number of data points in the original ordered data set the median is not included in either half.
288
+
- If there are an even number of data points in the original ordered data set, the sata set is split exactly in half.
287
289
288
290
The lower quartile value (`Q1`) is the median of the lower half of the data. The upper quartile value (`Q3`) is the median of the upper half of the data.
If the data array is empty or contains a non-numeric value, the method returns `undefined`.
356
358
359
+
#### percentile
360
+
361
+
```js
362
+
percentile(arr, k);
363
+
```
364
+
365
+
Returns the `k^{th}` percentile of the data array.
366
+
367
+
A percentile (or a centile) is a measure used in statistics indicating the value below which a given percentage of observations in a group3 of observations falls.
If the data array is empty or contains a non-numeric value, the method returns `undefined`. If the value of `k` is non-numeric and not in the interval `[0, 1]`, the method returns `undefined`.
374
+
357
375
### Measures of spread
358
376
359
377
These methods compute a measure of the variability in a sample or population, how much the sample or population tends to deviate from the typical or average values.
@@ -544,7 +562,25 @@ sum(arr);
544
562
Return the sum of all elements of a numeric data array `arr`. The method implement the [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) in order to minimise numerical error.
0 commit comments