Data
Methods
boxplot
Performs complete boxplot analysis including computation of notches and outliers.
Example
var data = [
-12, 14, 14, 14, 16, 18, 20, 20, 21, 23, 27, 27, 27, 29, 31,
31, 32, 32, 34, 36, 40, 40, 40, 40, 40, 42, 51, 56, 60, 88
];
boxplot( data );
returns {
// min: -12, q1: 20, median: 31, q3: 40, max: 88,
// iqr: 20, range: 100, size: 30,
// leftOutliers: { begin: 0, end: 0, count: 1, fence: 14 },
// rightOutliers: { begin: 29, end: 29, count: 1, fence: 60 },
// leftNotch: 25.230655727612252,
// rightNotch: 36.76934427238775
// }
Parameters
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
||
| coeff | number |
<optional> |
1.5 | used for outliers computation. |
| accessor | string number function |
<optional> |
required when elements of
|
Returns
consisting of min, q1, median, q3,
max, iqr, range, size along with leftNotch, and rightNotch.
The leftOutliers/rightOutliers (object), if present, contains the count, fence
and begin/end indexes to sortedData for easy extraction of exact values.
- Type
- object
difference
Computes the difference between each nth successive element of the
input data array. The default value for n is 1.
Example
difference( [ 1, 3, 5, 5, 9, 11, 11 ] );
// returns [ 2, 2, 0, 4, 2, 0 ]
difference( [ 1, 2, 4, 8, 16, 32, 64 ], 2 );
// returns [ 3, 6, 12, 24, 48 ]
Parameters
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
| data | Array.<number> | input data array. |
||
| n | number |
<optional> |
1 | defines the lag at which successive difference is computed. |
Returns
array containing the differences; it will be empty if lag =< data's length.
- Type
- Array.<number>
fiveNumSummary
Returns the five number summary from the sortedData.
Example
fiveNumSummary( [ 1, 1, 2, 2, 3, 3, 4, 4 ] );
// returns {
// q1: 1.25, median: 2.5, q3: 3.75, iqr: 2.5,
// size: 8, min: 1, max: 4, range: 3
// }
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
5-number summary consisting of min, q1, median, q3,
max along with iqr, range, and size.
- Type
- number
histogram
Generates histogram using Freedman–Diaconis method.
If both IQR and MAD are 0 then it automatically
switches to Sturges' Rule while ensuring minimum of 5 bins.
It attempts to reduce excessive sparsity of distribution,
if any, by adjusting the number of bins using Sturges' Rule.
Example
var data = [
12, 14, 14, 14, 16, 18, 20, 20, 21, 23, 27, 27, 27, 29, 31,
31, 32, 32, 34, 36, 40, 40, 40, 40, 40, 42, 51, 56, 60, 65
];
histogram( data );
// returns {
// classes: [
// { min: 12, mid: 19, max: 25 },
// { min: 25, mid: 32, max: 38 },
// { min: 38, mid: 45, max: 51 },
// { min: 51, mid: 58, max: 64 },
// { min: 64, mid: 71, max: 77 } ],
// frequencies: [ 10, 10, 7, 2, 1 ],
// q1: 20, q3: 40, iqr: 20, size: 30, min: 12, max: 65,range: 53
// }
Parameters
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
||
| dataPrecision | number |
<optional> |
0 | typically the minumum number of
decimal places observed in the |
| accessor | string number function |
<optional> |
required when elements of
|
Returns
conatining arrays classes and the corresponding frequencies.
Each element of classes array is an object with values for min/max (class intervals)
and mid point of a class.
In addition, the returned object
contains useful statistics like q1, q3, iqr, min, max, and range.
- Type
- object
mad
Returns the median of the sortedData.
Example
mad( [ 1, 1, 2, 2, 3, 3, 4, 4 ] );
// returns 1
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
median of the sortedData.
- Type
- number
max
Finds the maximum value in the x array.
Example
max( [ 99, 1, -1, +222, 0, -99 ] )
// returns 222
max( [ { x: 33 }, { x: 11 }, { x:44 } ], 'x' )
// returns 44
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| x | array | array containing 1 or more elements. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
maximum value from array x.
- Type
- object
mean
Comuptes the mean of numbers contained in the x array.
The computations are inspired by the method proposed by B. P. Welford.
Example
mean( [ 2, 3, 5, 7 ] )
// returns 4.25
mean( [ { x: 2 }, { x: 3 }, { x: 5 }, { x: 7 } ], 'x' )
// returns 4.25
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| x | array | array containing 1 or more elements. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
mean value.
- Type
- number
median
Returns the median of the sortedData.
Example
median( [ 1, 1, 2, 2, 3, 3, 4, 4 ] );
// returns 2.5
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
|
| accessor | string number function |
<optional> |
Useful when each element of
|
Returns
median of the sortedData.
- Type
- number
min
Finds the minimum value in the x array.
Example
min( [ 99, 1, -1, +222, 0, -99 ] )
// returns -99
min( [ { x: 33 }, { x: 11 }, { x:44 } ], 'x' )
// returns 11
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| x | array | array containing 1 or more elements. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
minimum value from array x.
- Type
- object
percentile
Returns the qth percentile from the sortedData. The computation is
based on Method 11 described in Quartiles in Elementary Statistics
by Eric Langford published in Journal of Statistics Education Volume 14, Number 3 (2006).
Example
percentile( [ 1, 1, 2, 2, 3, 3, 4, 4 ], 0.25 );
// returns 1.25
percentile( [ 1, 1, 2, 2, 3, 3, 4, 4 ], 0.75 );
// returns 3.75
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| sortedData | array | sorted in ascending order of value. |
|
| q | number | should be between 0 and 1 indicating percentile; for example, to get 25th percentile, it should be 0.25. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
qth percentile of sortedData.
- Type
- number
stdev
Comuptes the sample standard deviation of numbers contained in the x array.
The computations are inspired by the method proposed by B. P. Welford.
Example
stdev( [ 2, 3, 5, 7 ] )
// returns 2.217355782608345
stdev( [ { x: 2 }, { x: 3 }, { x: 5 }, { x: 7 } ], 'x' )
// returns 2.217355782608345
Parameters
| Name | Type | Attributes | Description |
|---|---|---|---|
| x | array | array containing 1 or more elements. |
|
| accessor | string number function |
<optional> |
required when elements of
|
Returns
standard deviation of sample.
- Type
- number