Constructor
new Univariate(args)
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object |
Properties
|
- Source:
Methods
add(…data) → {Univariate}
Add value(s) to sample.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Number |
<repeatable> |
Number(s) to add to sample |
- Source:
Returns:
this (chainable)
- Type
- Univariate
Examples
for (let i=0; i<10000; i++)
stat.add(-Math.log(Math.random()));
// creates exponential distribution
stat.add( 1,2,3,4,5,6 );
// a d6
addWeighted(pairs) → {Univariate}
Add values to sample, with weights.
Parameters:
Name | Type | Description |
---|---|---|
pairs |
Array.<Array.<number>> | Each pair is an array with two numbers: [ value, quantity ]. Negative quantity is allowed and means we're erasing data. |
- Source:
Returns:
this (chainable)
- Type
- Univariate
Example
stat.addWeighted( [ [0.1, 5], [0.2, 4], [0.3, 3] ] )
// adds 0.1 x 5, 0.2 x 4, 0.3 x 3
cdf(x) → {Number}
Cumulative distribution function, i.e. P(value < x).
This is the inverse of quantile.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number |
- Source:
Returns:
probability
- Type
- Number
clone(argsopt) → {Univariate}
create a copy of sample object, possibly modifying precision
settings and/or filtering data.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object |
<optional> |
Properties
|
- Source:
Returns:
copy of the original object
- Type
- Univariate
count() → {Integer}
Number of values in the sample.
- Source:
Returns:
count
- Type
- Integer
E(fun) → {Number}
Calculate expected value of a given function over the sample.
Parameters:
Name | Type | Description |
---|---|---|
fun |
function |
- Source:
Returns:
- Type
- Number
getBins()
Returns a sorted list of pairs containing numbers in the sample
and their respective counts.
See addWeighted().
- Source:
histogram(args) → {Array}
Histogram based on the sample
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object |
Properties
|
- Source:
Returns:
Array of triplets: [barHeight, leftBorder, rightBorder ].
rightBorder equals to the next bar's leftBorder.
- Type
- Array
kurtosis() → {Number|undefined}
Kurtosis is a measure of how much of the distribution is
contained in the "tails".
Equals to 4th standardized moment minus 3,
with a correction.
- Source:
Returns:
- Type
- Number | undefined
max() → {Number}
Maximal value in the sample.
This value is somewhat rounded up to guarantee
it is greater than _any_ value in the sample.
- Source:
Returns:
Maximum value
- Type
- Number
mean() → {Number}
Average value of the sample.
- Source:
Returns:
- Type
- Number
median() → {Number}
Returns x such that half of the sample is less than x.
Same as quantile(0.5).
- Source:
Returns:
x
- Type
- Number
min() → {Number}
Minimal value in the sample.
This value is somewhat rounded down to guarantee
it is less than _any_ value in the sample.
- Source:
Returns:
Minimum value
- Type
- Number
moment(power, offsetopt) → {Number}
Moment of nth power, i.e. E((x-offset)**power)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
power |
Integer | Power to raise to. | |
offset |
Number |
<optional> |
Number to subtract. Default is mean. |
- Source:
Returns:
- Type
- Number
momentAbs(power, offsetopt) → {Number}
Absolute moment of nth power, i.e. E(|x-offset|**power)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
power |
Number | 1 | Power to raise to. May be fractional. Default is 1. | |
offset |
Number |
<optional> |
Number to subtract. Default is mean. |
- Source:
Returns:
- Type
- Number
momentStd(power) → {Number}
Standardized moment of nth power, i.e. nth moment / stdev**n.
Parameters:
Name | Type | Description |
---|---|---|
power |
Integer |
- Source:
Returns:
- Type
- Number
percentile(p) → {Number}
Returns x such that P(value < x) === p%.
Same as quantile(p/100).
Parameters:
Name | Type | Description |
---|---|---|
p |
Number |
- Source:
Returns:
x
- Type
- Number
quantile(p) → {Number}
A number x such that P(value <= x) === p
Parameters:
Name | Type | Description |
---|---|---|
p |
Number | from 0 to 1 |
- Source:
Returns:
value
- Type
- Number
Example
const stat = new Univariate();
stat.add( 1,2,3,4,5 );
stat.quantile( 0.2 ); // slightly greater than 1
stat.quantile( 0.5 ); // 3
skewness() → {Number|undefined}
Skewness is a measure of the asymmetry of a distribution.
Equals to 3rd standardized moment times n^2/(n-1)(n-2) correction
Undefined if there are less than 3 data points.
- Source:
Returns:
- Type
- Number | undefined
stdev() → {Number}
Standard deviation of the sample.
Bessel's correction is used:
stdev = sqrt( E<(x - E)**2> * n/(n-1) )
- Source:
Returns:
Standard deviation
- Type
- Number
sumOf(fun) → {Number}
Sum of arbitrary function over the sample.
Parameters:
Name | Type | Description |
---|---|---|
fun |
function | Number->Number |
- Source:
Returns:
- Type
- Number
Examples
stat.sumOf( x => 1 ); // same as stat.count()
stat.sumOf( x => x ); // same as stat.count() * stat.mean()
toJSON() → {Object}
Serialization of the sample.
- Source:
Returns:
plain data structure that can serve
as an argument to new().
- Type
- Object