jStat is a statistical library written in JavaScript that allows you to perform advanced statistical operations without the need of a dedicated statistical language (e.g. MATLAB or R). It is available for download on Github.
Calculations are done by static methods, while working with groups of numbers is handled by the instance methods.
Here is a pseudo example of what is happening in core.js
:
jStat.min = function( arr ) {
return Math.min.apply( null, arr );
}
jStat.prototype.min = function() {
var i = 0,
newval = [];
while( newval.push( jStat.min( this[i] )), ++i < this.length );
return newval;
}
jStat.min
does the actual calculation on the array, while jStat.prototype.min
is a wrapper to help work with the jStat object.
The reason for this approach is to allow for maxium flexibility to other developers who want to extend jStat, while allowing for easy creation of wrappers.
This way extending jStat requires minimal performance overhead and allows for more unique wrappers to be created.
Remember: Static methods almost always return native JavaScript types. Instance methods always return a jStat object.
Here is a simple example on the difference in usage between the static and instance methods:
var myVect = [2,6,4,7,2,7,4],
jObj = jStat( myVect );
// calculate the sum of the the vector
jStat.sum( myVect ) === 32;
jObj.sum() === 32;
Now say we want to do several operations on the vector (e.g. sum, min, max, and standard deviation). This can be accomplished using the static methods, but each will need to be called separately. By using the jStat object we can pass callback functions and chain the execution of each operation:
jObj.sum( function( val ) {
// val === sum
}).min( function( val ) {
// val === min
}).max( function( val ) {
// val === max
}).stdev( function( val ) {
// val === st. dev.
});
This method sets each calculation to be executed in an asynchronous queue. Very useful method of preventing blocking when working with large data sets.
Let's look at a few chaining and shorthand examples:
jStat( 0, 1, 11 ) === jStat( jStat.seq( 0, 1, 11 ));
jStat().rand( 4, 4 ) === jStat( jStat.rand( 4, 4 ));
jStat().create( 5, function( x, y ) {
return ( x + Math.random()) / ( y + Math.random());
}).min( true, function( x ) {
// do something with the min value
}).beta( 0.5, 0.5 ).pdf(); // generate and return the pdf
// of the beta function for all values
Core functionality include methods that generate and analyse vectors or matrices.
The jStat object can function in several capacities, as demonstrated below. In all cases, jStat will always return an instance of itself.
jStat( array[, fn] )
Creates a new jStat object from either an existing array or jStat object. For example, create a new jStat matrix by doing the following:
var matrix = jStat([[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]);
If an existing jStat object is passed as an argument then it will be cloned into a new object:
var stat1 = jStat([[ 1, 2 ],[ 3, 4 ]]),
stat2 = jStat( stat1 );
To transform the data on creation, pass a function as the final argument:
jStat([[ 1, 2 ],[ 3, 4 ]], function( x ) {
return x * 2;
});
jStat( start, stop, count[, fn ])
To create a sequence then pass numeric values in the same form jStat.seq()
would be used:
var vector = jStat( 0, 1, 5 );
// vector === [[ 0, 0.25, 0.5, 0.75, 1 ]]
By passing a function the sequence value can be manipulated:
var vector = jStat( 0, 1, 5, function( x ) {
return x * 2;
});
// vector === [[ 0, 0.5, 1, 1.5, 2 ]];
The second argument passed to the function is the count (starting from 0). Using this we can create a multidimensional array (useful for plotting data):
var betaGraph = jStat( 0, 1, 11, function( x, cnt ) {
return [ jStat.beta.pdf( x, alpha, beta ), cnt ];
});
jStat()
A chainable shortcut in the API exists to allow for filling in the data after object creation.
So creating jStat
objects from methods like rand()
can be accomplished in one of the following ways:
// pass the generated random 3x3 matrix to jStat
jStat( jStat.rand( 3 ));
// or create an empty instance that is filled in afterwards
jStat().rand( 3 );
Returns the count of rows in a matrix.
rows( array )
var matrix = [[1,2,3],[4,5,6]];
jStat.rows( matrix ) === 2;
fn.rows( [callback] )
jStat( matrix ).rows() === 2;
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).rows(function( d ) {
// d === 2
});
Returns a array from matrix row.
rowa([[1,2],[3,4]]) === [1,2];
Returns the number of columns in a matrix.
cols( array )
var matrix = [[1,2,3],[4,5,6]];
jStat.cols( matrix ) === 3;
fn.cols( [callback] )
jStat( matrix ).cols() === 3;
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).cols(function( d ) {
// d === 3
});
Returns an array from matrix column (col()
will return a matrix form instead of an array form).
cola([[1,2],[3,4]]) === [1,3];
Slices matrix as numpy style.
A=[[1,2,3],[4,5,6],[7,8,9]];
slice(A,{row:{end:2},col:{start:1}}) === [[2,3],[5,6]];
slice(A,1,{start:1}) === [5,6];
Do slice assign as numpy style.
A = [[1,2,3],[4,5,6],[7,8,9]];
sliceAssign(A,{row : {start : 1}, col : {start : 1}},[[0,0],[0,0]]);
A = [[1,2,3],[4,0,0],[7,0,0]];
Returns an object with the dimensions of a matrix.
dimensions( array )
var matrix = [[1,2,3],[4,5,6]];
jStat.dimensions( matrix ) === { cols: 3, rows: 2 };
fn.dimensions( [callback] )
jStat( matrix ).dimensions() === { cols: 3, rows: 2 };
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).dimensions(function( d ) {
// d === { cols: 3, rows: 2 }
});
Returns a specified row of a matrix.
row( array, index )
var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.row( matrix, 0 ) === [1,2,3];
jStat.row( matrix, [0,1] ) === [[1,2,3],[4,5,6]]
fn.row( index[, callback] )
jStat( matrix ).row( 0 ) === jStat([1,2,3]);
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).row( 0, function( d ) {
// d === jStat([1,2,3])
});
Returns the specified column as a column vector.
col( index )
var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.col( matrix, 0 ) === [[1],[4],[7]];
jStat.col( matrix,[0,1] ) === [[1,2],[4,5],[7,8]]
fn.col( index[, callback] )
jStat( matrix ).col( 0 ) === jStat([[1],[4],[7]]);
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).col( 0, function( d ) {
// d === jStat([[1],[3]])
})
Returns the diagonal of a matrix.
diag( array )
var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.diag( matrix ) === [[1],[5],[9]];
fn.diag( [callback] )
jStat( matrix ).diag() === jStat([[1],[5],[9]]);
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).diag(function( d ) {
// d === jStat([[1],[5],[9]])
});
Returns the anti-diagonal of the matrix.
antidiag( array )
var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.antidiag( matrix ) === [[3],[5],[7]];
fn.antidiag( [callback] )
jStat( matrix ).antidiag() === jStat([[3],[5],[7]]);
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).antidiag(function( d ) {
// d === jStat([[3],[5],[7]])
});
Creates a new diagonal matrix by given 1d diag array.
jStat.diagonal([1,2,3]) === [[1,0,0],[0,2,0],[0,0,3]];
Transposes a matrix.
transpose( array )
var matrix = [[1,2],[3,4]];
jStat.transpose( matrix ) === [[1,3],[2,4]];
fn.transpose( [callback] )
jStat( matrix ).transpose() === [[1,3],[2,4]];
Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note this
within the callback refers to the calling jStat object.
jStat( matrix ).transpose(function( d ) {
// d === jStat([[1,3],[2,4]])
})
Maps a function to all values and return a new object.
map( array, fn )
var matrix = [[1,2],[3,4]];
jStat.map( matrix, function( x ) {
return x * 2;
});
// returns [[2,4],[6,8]]
fn.map( fn )
jStat( matrix ).map(function( x ) {
return x * 2;
});
Cumulatively reduces values using a function and return a new object.
cumreduce( array, fn )
var matrix = [[1,2],[3,4]];
jStat.cumreduce( matrix, function( a, b ) {
return a + b;
});
// returns [[1,3],[3,7]]
fn.cumreduce( fn )
jStat( matrix ).cumreduce(function( a, b ) {
return a + b;
});
Destructively maps to an array.
alter( array, fn )
var matrix = [[1,2],[3,4]];
jStat.alter( matrix, function( x ) {
return x * 2;
});
// matrix === [[2,4],[6,8]]
fn.alter( fn )
var matrix = [[1,2],[3,4]];
jStat( matrix ).alter( function( x ) {
return x * 2;
});
Creates a row by col matrix using the supplied function.
If col
is omitted then it will default to value row
.
create( row[, col], fn )
jStat.create( 2, function( row, col ) {
return row + col;
});
// returns [[0,1],[1,2]]
fn.create( row[, col], fn )
Use this technique to create matrices in jStat instances.
jStat().create( 2, function( row, col ) {
return row + col;
});
// returns jStat([[0,1],[1,2]])
Creates a row by col matrix of all zeros.
If col
is omitted then it will default to value row
.
zeros( row[, col] )
jStat.zeros( 2 );
// returns [[0,0],[0,0]]
fn.zeros( row[, col] )
Use this technique to create matrices in jStat instances.
jStat().zeros( 2 );
// returns jStat([[0,0],[0,0]])
Creates a row by col matrix of all ones.
If col
is omitted then it will default to value row
.
ones( row[, col] )
jStat.zeros( 2 );
// returns [[0,0],[0,0]]
fn.ones( row[, col] )
Use this technique to create matrices in jStat instances.
jStat().ones( 2 );
// returns jStat([[0,0],[0,0]])
Creates a matrix of normally distributed random numbers.
If col
is omitted then it will default to value row
.
rand( row[, col] )
jStat.rand( 3 );
fn.rand( row[, col] )
Use this technique to create matrices in jStat instances.
jStat().rand( 3 );
Returns a copy of given matrix.
Creates an identity matrix of row by col.
If col
is omitted then it will default to value row
.
identity( row[, col] )
jStat.identity( 2 );
// returns [[1,0],[0,1]]
fn.identity( row[, col] )
Use this technique to create matrices in jStat instances.
jStat().identity( 2 );
Creates an arithmetic sequence by given length.
jStat.seq(1,5,9) === [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5];
Creates an arithmetic sequence by given step.
arange(5) === [0,1,2,3,4]
arange(1,5) === [1,2,3,4]
arange(5,1,-1) === [5,4,3,2]
Sets all values in the vector or matrix to zero.
clear( array )
var tmp = [1,2,3];
jStat.clear( tmp );
// tmp === [0,0,0]
fn.clear( [callback] )
jStat( 0, 1, 3 ).clear();
// returns [[0,0,0]]
If a callback is passed then the original object is not altered.
var obj = jStat( 0, 1, 3 );
obj.clear(function() {
// this === [ 0, 0, 0 ]
});
// obj === [ 0, 0.5, 1 ]
Tests if a matrix is symmetric.
symmetric( array )
jStat.symmetric([[1,2],[2,1]]) === true
fn.symmetric( [callback] )
jStat([[1,2],[2,1]]).symmetric() === true
Can pass a callback to maintain chainability.
jStat([[1,2],[2,1]]).symmetric(function( result ) {
// result === true
});
Utilities that are used throughout the jStat library.
Calculates the decimal shift for the IEEE 754 floating point calculation correction.
Tests if arg
is an array.
Tests if arg
is a function.
Tests if arg
is a number and not NaN
.
sum( array )
Returns the sum of the array
vector.
jStat.sum([1,2,3]) === 6
fn.sum( [bool][, callback] )
Returns the sum of a vector or matrix columns.
jStat( 1, 5, 5 ).sum() === 15
jStat([[1,2],[3,4]]).sum() === [ 4, 6 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).sum(function( result ) {
// result === 15
});
If pass boolean true as first argument, then return sum of entire matrix.
jStat([[1,2],[3,4]]).sum( true ) === 10
And the two can be combined.
jStat([[1,2],[3,4]]).sum(true, function( result ) {
// result === 10
});
sumsqrd( array )
Returns the sum squared of the array
vector.
jStat.sumsqrd([1,2,3]) === 14
fn.sumsqrd( [bool][, callback] )
Returns the sum squared of a vector or matrix columns.
jStat( 1, 5, 5 ).sumsqrd() === 55
jStat([[1,2],[3,4]]).sumsqrd() === [ 10, 20 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).sumsqrd(function( result ) {
// result === 55
});
If pass boolean true as first argument, then return sum squared of entire matrix.
jStat([[1,2],[3,4]]).sumsqrd( true ) === 650
And the two can be combined.
jStat([[1,2],[3,4]]).sumsqrd(true,function( result ) {
// result === 650
});
sumsqerr( array )
Returns the sum of squared errors of prediction of the array
vector.
jStat.sumsqerr([1,2,3]) === 2
fn.sumsqerr( [bool][, callback] )
Returns the sum of squared errors of prediction of a vector or matrix columns.
jStat( 1, 5, 5 ).sumsqerr() === 10
jStat([[1,2],[3,4]]).sumsqerr() === [ 2, 2 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).sumsqerr(function( result ) {
// result === 55
});
If pass boolean true as first argument, then return sum of squared errors of entire matrix.
jStat([[1,2],[3,4]]).sumsqerr( true ) === 0
And the two can be combined.
jStat([[1,2],[3,4]]).sumsqerr(true,function( result ) {
// result === 0
});
sumrow( array )
Returns the sum of the array
vector in row-based order.
jStat.sumrow([1,2,3]) === 6
fn.sumrow( [bool][, callback] )
Returns the sum of a vector or matrix rows.
jStat( 1, 5, 5 ).sumrow() === 15
jStat([[1,2],[3,4]]).sumrow() === [ 3, 7 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).sumrow(function( result ) {
// result === 15
});
If pass boolean true as first argument, then return sum of entire matrix.
jStat([[1,2],[3,4]]).sumrow( true ) === 10
And the two can be combined.
jStat([[1,2],[3,4]]).sumrow(true,function( result ) {
// result === 10
});
product( array )
Returns the product of the array
vector.
jStat.product([1,2,3]) === 6
fn.product( [bool][, callback] )
Returns the product of a vector or matrix columns.
jStat( 1, 5, 5 ).product() === 120
jStat([[1,2],[3,4]]).product() === [ 3, 8 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).product(function( result ) {
// result === 120
});
If pass boolean true as first argument, then return sumsqerr of entire matrix.
jStat([[1,2],[3,4]]).product( true ) === 24
And the two can be combined.
jStat([[1,2],[3,4]]).product(true,function( result ) {
// result === 24
});
min( array )
Returns the minimum value of the array
vector.
jStat.min([1,2,3]) === 1
fn.min( [bool][, callback] )
Returns the minimum value of a vector or matrix columns.
jStat( 1, 5, 5 ).min() === 1
jStat([[1,2],[3,4]]).min() === [ 1, 2 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).min(function( result ) {
// result === 1
});
If pass boolean true as first argument, then return minimum of entire matrix.
jStat([[1,2],[3,4]]).min( true ) === 1
And the two can be combined.
jStat([[1,2],[3,4]]).min(true,function( result ) {
// result === 1
});
max( array )
Returns the maximum value of the array
vector.
jStat.max([1,2,3]) === 3
fn.max( [bool][, callback] )
Returns the maximum value of a vector or matrix columns.
jStat( 1, 5, 5 ).max() === 5
jStat([[1,2],[3,4]]).max() === [ 3, 4 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).max(function( result ) {
// result === 5
});
If pass boolean true as first argument, then return maximum of entire matrix.
jStat([[1,2],[3,4]]).max( true ) === 4
And the two can be combined.
jStat([[1,2],[3,4]]).max(true,function( result ) {
// result === 4
});
mean( array )
Returns the mean of the array
vector.
jStat.mean([1,2,3]) === 2
fn.max( [bool,][callback] )
Returns the max of a vector or matrix columns.
jStat( 1, 5, 5 ).mean() === 3
jStat([[1,2],[3,4]]).mean() === [ 2, 3 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).mean(function( result ) {
// result === 3
});
If pass boolean true as first argument, then return mean of entire matrix.
jStat([[1,2],[3,4]]).mean( true ) === 2.5
And the two can be combined.
jStat([[1,2],[3,4]]).mean(true,function( result ) {
// result === 2.5
});
meansqerr( array )
Returns the mean squared error of the array
vector.
jStat.meansqerr([1,2,3]) === 0.66666...
fn.meansqerr( [bool][, callback] )
Returns the mean squared error of a vector or matrix columns.
jStat( 1, 5, 5 ).meansqerr() === 2
jStat([[1,2],[3,4]]).meansqerr() === [ 1, 1 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).meansqerr(function( result ) {
// result === 2
});
If pass boolean true as first argument, then return mean squared error of entire matrix.
jStat([[1,2],[3,4]]).meansqerr( true ) === 0
And the two can be combined.
jStat([[1,2],[3,4]]).meansqerr(true,function( result ) {
// result === 0
});
geomean( array )
Returns the geometric mean of the array
vector.
jStat.geomean([4,1,1/32]) === 0.5
fn.geomean( [bool][, callback] )
Returns the geometric mean of a vector or matrix columns.
jStat([4,1,1\32]).geomean() === 0.5
jStat([[1,2],[3,4]]).geomean() === [ 1.732..., 2.828... ]
If callback is passed then will pass result as first argument.
jStat([4,1,1\32]).geomean(function( result ) {
// result === 0.5
});
If pass boolean true as first argument, then return geometric mean of entire matrix.
jStat([[1,2],[3,4]]).geomean( true ) === 2.213...
And the two can be combined.
jStat([[1,2],[3,4]]).geomean(true,function( result ) {
// result === 2.213...
});
median( array )
Returns the median of the array
vector.
jStat.median([1,2,3]) === 2
fn.median( [bool][, callback] )
Returns the median of a vector or matrix columns.
jStat( 1, 5, 5 ).median() === 3
jStat([[1,2],[3,4]]).median() === [ 2, 3 ]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).median(function( result ) {
// result === 3
});
If pass boolean true as first argument, then return median of entire matrix.
jStat([[1,2],[3,4]]).median( true ) === 2.5
And the two can be combined.
jStat([[1,2],[3,4]]).median(true,function( result ) {
// result === 2.5
});
cumsum( array )
Returns an array of partial sums in the sequence.
jStat.cumsum([1,2,3]) === [1,3,6]
fn.cumsum( [bool][, callback] )
Returns an array of partial sums for a vector or matrix columns.
jStat( 1, 5, 5 ).cumsum() === [1,3,6,10,15]
jStat([[1,2],[3,4]]).cumsum() === [[1,4],[2,6]]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).cumsum(function( result ) {
// result === [1,3,6,10,15]
});
If pass boolean true as first argument, then return cumulative sums of the matrix.
jStat([[1,2],[3,4]]).cumsum( true ) === [[1,3],[3,7]]
And the two can be combined.
jStat([[1,2],[3,4]]).cumsum(true,function( result ) {
// result === ...
});
cumprod( array )
Returns an array of partial products in the sequence.
jStat.cumprod([2,3,4]) === [2,6,24]
fn.cumprod( [bool][, callback] )
Returns an array of partial products for a vector or matrix columns.
jStat( 1, 5, 5 ).cumprod() === [1,2,6,24,120]
jStat([[1,2],[3,4]]).cumprod() === [[1,3],[2,8]]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).cumprod(function( result ) {
// result === [1,2,6,24,120]
});
If pass boolean true as first argument, then return cumulative products of the matrix.
jStat([[1,2],[3,4]]).cumprod( true ) === [[1,2],[3,12]]
And the two can be combined.
jStat([[1,2],[3,4]]).cumprod(true,function( result ) {
// result === ...
});
diff( array )
Returns an array of the successive differences of the array.
jStat.diff([1,2,2,3]) === [1,0,1]
fn.diff( [bool][, callback] )
Returns an array of successive differences for a vector or matrix columns.
jStat([1,2,2,3]).diff() === [1,0,1]
jStat([[1,2],[3,4],[1,4]]).diff() === [[2,-2],[2,0]]
If callback is passed then will pass result as first argument.
jStat([[1,2],[3,4],[1,4]]).diff(function( result ) {
// result === [[2,-2],[2,0]]
});
If pass boolean true as first argument, then return successive difference for the whole matrix.
jStat([[1,2],[3,4],[1,4]]).diff(true) === [0,2]
And the two can be combined.
jStat([[1,2],[3,4],[1,4]]).diff(true,function( result ) {
// result === [0,2]
});
rank( array )
Returns an array of the ranks of the array.
jStat.rank([1, 2, 2, 3]) === [1, 2.5, 2.5, 4]
fn.rank( [bool][, callback] )
Returns an array of ranks for a vector or matrix columns.
jStat([1, 2, 2, 3]).rank() === [1, 2.5, 2.5, 4]
jStat([[1, 2], [3, 4], [1, 4]]).rank() === [[1.5, 3, 1.5], [1, 2.5, 2.5]]
If callback is passed then will pass result as first argument.
jStat([[1, 2], [3, 4], [1, 4]]).rank(function( result ) {
// result === [[1.5, 3, 1.5], [1, 2.5, 2.5]]
});
If pass boolean true as first argument, then return rank for the whole matrix.
jStat([[1, 2], [3, 4], [1, 4]]).rank(true) === [2, 5, 2, 5, 2, 5]
And the two can be combined.
jStat([[1, 2], [3, 4], [1, 4]]).rank(true, function( result ) {
// result === [2, 5, 2, 5, 2, 5]
});
mode( array )
Returns the mode of the array
vector.
If there are multiple modes then mode()
will return all of them.
jStat.mode([1,2,2,3]) === 2
jStat.mode([1,2,3]) === [1,2,3]
fn.mode( [bool][, callback] )
Returns the mode for a vector or matrix columns.
jStat([1,2,2,3]).mode() === 2
jStat([[1,2],[3,4],[1,4]]).mode() === [1,4]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).mode(function( result ) {
// result === false
});
If pass boolean true as first argument, then the matrix will be treated as one dimensional.
jStat([[5,4],[5, 2], [5,2]]).mode( true ) === 5
range( array )
Returns the range of the array
vector.
jStat.range([1,2,3]) === 2
fn.range( [bool][, callback] )
Returns the range for a vector or matrix columns.
jStat([1,2,3]).range() === 2
jStat([[1,2],[3,4]]).range() === [2,2]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).range(function( result ) {
// result === 4
});
If pass boolean true as first argument, then return range of the matrix.
jStat([[1,2],[3,5]]).range( true ) === true
And the two can be combined.
jStat([[1,2],[3,5]]).range(true,function( result ) {
// result === 1
});
variance( array[, flag] )
Returns the variance of the array
vector.
By default, the population variance is calculated.
Passing true
to flag
indicates to compute the sample variance instead.
jStat.variance([1,2,3,4]) === 1.25
jStat.variance([1,2,3,4],true) === 1.66666...
fn.variance( [bool][, callback] )
Returns the variance for a vector or matrix columns.
Note: Cannot pass flag to indicate between population or sample for matrices. There is a feature request for this on Issue #51.
jStat([1,2,3,4]).variance() === 1.25
jStat([[1,2],[3,4]]).variance() === [1,1]
If callback is passed then will pass result as first argument.
jStat( 1, 5, 5 ).variance(function( result ) {
// result === 2
});
If pass boolean true as first argument, then return variance of the matrix.
jStat([[1,2],[3,5]]).variance( true ) === 0.140625
And the two can be combined.
jStat([[1,2],[3,5]]).variance(true,function( result ) {
// result === 0.140625
});
pooledvariance( arrays )
Returns the pooled (sample) variance of an array of vectors. Assumes the population variance of the vectors are the same.
jStat.pooledvariance([[1,2],[3,4]]) === 0.5
deviation( array )
Returns the deviation of the array
vector.
jStat.deviation([1,2,3,4]) === [-1.5, -0.5, 0.5, 1.5]
fn.deviation( [bool][, callback] )
Returns the deviation for a vector or matrix columns.
jStat([1,2,3,4]).deviation() === [-1.5, -0.5, 0.5, 1.5]
jStat([[1,2],[3,4]]).deviation() === [[-1,1],[-1,1]]
If callback is passed then will pass result as first argument.
jStat( 1, 4, 4 ).deviation(function( result ) {
// result === [-1.5, -0.5, 0.5, 1.5]
});
If pass boolean true as first argument, then return variance of the matrix.
jStat([[1,2],[3,5]]).deviation( true ) === [-0.5, 0.5, -1, 1]
And the two can be combined.
jStat([[1,2],[3,5]]).deviation(true,function( result ) {
// result === [-0.5, 0.5, -1, 1]
});
stdev( array[, flag] )
Returns the standard deviation of the array
vector.
By default, the population standard deviation is returned.
Passing true
to flag
returns the sample standard deviation.
The 'sample' standard deviation is also called the 'corrected standard deviation', and is an unbiased estimator of the population standard deviation. The population standard deviation is also the 'uncorrected standard deviation', and is a biased but minimum-mean-squared-error estimator.
jStat.stdev([1,2,3,4]) === 1.118...
jStat.stdev([1,2,3,4],true) === 1.290...
fn.stdev( [bool][, callback] )
Returns the standard deviation for a vector or matrix columns.
Note: Cannot pass flag
to indicate between population or sample for matrices.
There is a feature request for this on Issue #51.
jStat([1,2,3,4]).stdev() === 1.118...
jStat([1,2,3,4]).stdev(true) === 1.290...
jStat([[1,2],[3,4]]).stdev() === [1,1]
If callback is passed then will pass result as first argument.
jStat( 1, 4, 4 ).stdev(function( result ) {
// result === 1.118...
});
jStat( 1, 4, 4 ).stdev(true,function( result ) {
// result === 1.290...
});
If pass boolean true as first argument, then return variance of the matrix.
jStat([[1,2],[3,5]]).stdev( true ) === 0.25
And the two can be combined.
jStat([[1,2],[3,5]]).stdev(true,function( result ) {
// result === 0.25
});
pooledstdev( arrays )
Returns the pooled (sample) standard deviation of an array of vectors. Assumes the population standard deviation of the vectors are the same.
jStat.pooledstdev([[1,2],[3,4]]) === 0.707...
meandev( array )
Returns the mean absolute deviation of the array
vector.
jStat.meandev([1,2,3,4]) === 1
fn.meandev( [bool][, callback] )
Returns the mean absolute deviation for a vector or matrix columns.
jStat([1,2,3,4]).meandev() === 1
jStat([[1,2],[3,4]]).meandev() === [1,1]
If callback is passed then will pass result as first argument.
jStat( 1, 4, 4 ).meandev(function( result ) {
// result === 1
});
If pass boolean true as first argument, then return mean absolute deviation of the matrix.
jStat([[1,2],[3,5]]).meandev( true ) === 0.25
And the two can be combined.
jStat([[1,2],[3,5]]).meandev(true,function( result ) {
// result === 0.25
});
meddev( array )
Returns the median absolute deviation of the array
vector.
jStat.meddev([1,2,3,4]) === 1
fn.meddev( [bool][, callback] )
Returns the median absolute deviation for a vector or matrix columns.
jStat([1,2,3,4]).meddev() === 1
jStat([[1,2],[3,4]]).meddev() === [1,1]
If callback is passed then will pass result as first argument.
jStat( 1, 4, 4 ).meddev(function( result ) {
// result === 1
});
If pass boolean true as first argument, then return median absolute deviation of the matrix.
jStat([[1,2],[3,5]]).meddev( true ) === 0.25
And the two can be combined.
jStat([[1,2],[3,5]]).meddev(true,function( result ) {
// result === 0.25
});
skewness( array )
Returns the skewness of the array
vector (third standardized moment).
jStat.skewness([1,2,2,3,5]) === 0.75003...
kurtosis( array )
Returns the excess kurtosis of the array
vector (fourth standardized moment - 3).
jStat.kurtosis([1,2,3,4]) === -0.63610...
coeffvar( array )
Returns the coefficient of variation of the array
vector.
jStat.coeffvar([1,2,3,4]) === 0.447...
fn.coeffvar( [bool][, callback] )
Returns the coefficient of variation for a vector or matrix columns.
jStat([1,2,3,4]).coeffvar() === 0.447...
jStat([[1,2],[3,4]]).coeffvar() === [0.5,0.333...]
If callback is passed then will pass result as first argument.
jStat( 1, 4, 4 ).coeffvar(function( result ) {
// result === 0.447...
});
If pass boolean true as first argument, then return coefficient of variation of the matrix.
jStat([[1,2],[3,5]]).coeffvar( true ) === 0.142...
And the two can be combined.
jStat([[1,2],[3,5]]).coeffvar(true,function( result ) {
// result === 0.142...
});
quartiles( array )
Returns the quartiles of the array
vector.
jStat.quartiles( jStat.seq(1,100,100)) === [25,50,75]
fn.quartiles( [callback] )
Returns the quartiles for a vector or matrix columns.
jStat(1,100,100).quartiles() === [25,50,75]
jStat(1,100,100,function( x ) {
return [x,x];
}).quartiles() === [[25,50,75],[25,50,75]]
If callback is passed then will pass result as first argument.
jStat(1,100,100).quartiles(function( result ) {
// result === [25,50,75]
});
quantiles( dataArray, quantilesArray[, alphap[, betap]] )
Like quartiles, but calculate and return arbitrary quantiles of the dataArray
vector
or matrix (column-by-column).
jStat.quantiles([1, 2, 3, 4, 5, 6],
[0.25, 0.5, 0.75]) === [1.9375, 3.5, 5.0625]
Optional parameters alphap and betap govern the quantile estimation method. For more details see the Wikipedia page on quantiles or scipy.stats.mstats.mquantiles documentation.
percentile( dataArray, k, [exclusive] )
Returns the k-th percentile of values in the dataArray
range, where k is in the range 0..1, exclusive.
Passing true for the exclusive parameter excludes both endpoints of the range.
jStat.percentile([1, 2, 3, 4], 0.3) === 1.9;
jStat.percentile([1, 2, 3, 4], 0.3, true) === 1.5;
percentileOfScore( dataArray, score[, kind] )
The percentile rank of score in a given array. Returns the percentage
of all values in dataArray
that are less than (if kind == 'strict'
) or
less or equal than (if kind == 'weak'
) score. Default is 'weak'
.
jStat.percentileOfScore([1, 2, 3, 4, 5, 6], 3), 0.5, 'weak') === 0.5;
histogram( dataArray[, numBins] )
The histogram data defined as the number of dataArray
elements found in
equally sized bins across the range of dataArray
. Default number
of bins is 4.
jStat.histogram([100, 101, 102, 230, 304, 305, 400], 3) === [3, 1, 3];
covariance( array1, array2 )
Returns the covariance of the array1
and array2
vectors.
var seq = jStat.seq( 0, 10, 11 );
jStat.covariance( seq, seq ) === 11;
corrcoeff( array1, array2 )
Returns the population correlation coefficient of the array1
and array2
vectors (Pearson's Rho).
var seq = jStat.seq( 0, 10, 11 );
jStat.corrcoeff( seq, seq ) === 1;
spearmancoeff( array1, array2 )
Returns the rank correlation coefficient of the array1
and array2
vectors (Spearman's Rho).
jStat.spearmancoeff([1, 2, 3, 4], [5, 6, 9, 7]) == 0.8;
jStat.spearmancoeff([1, 2, 2, 4], [5, 2, 5, 7]) == 0.5;
Returns the value of x
in the Beta distribution with parameters alpha
and beta
.
Returns the value of x
in the cdf for the Beta distribution with parameters alpha
and beta
.
Returns the value of p
in the inverse of the cdf for the Beta distribution with parameters alpha
and beta
.
Returns the mean of the Beta distribution with parameters alpha
and beta
.
Returns the median of the Beta distribution with parameters alpha
and beta
.
Returns the mode of the Beta distribution with parameters alpha
and beta
.
Returns a random number whose distribution is the Beta distribution with parameters alpha
and beta
.
Returns the variance of the Beta distribution with parameters alpha
and beta
.
The F Distrbution is used frequently in analyses of variance. The distribution is parameterized by two degrees of freedom (df1
and df2
). It is defined continuously on x in [0, infinity).
In all cases, df1
is the "numerator degrees of freedom" and df2
is the "denominator degrees of freedom", which parameterize the distribtuion.
Given x
in the range [0, infinity), returns the probability density of the (central) F distribution at x
.
This function corresponds to the df(x, df1, df2)
function in R.
Given x in the range [0, infinity), returns the cumulative probability density of the central F distribution. That is, jStat.centralF.cdf(2.5, 10, 20)
will return the probability that a number randomly selected from the central F distribution with df1 = 10
and df2 = 20
will be less than 2.5.
This function corresponds to the pf(q, df1, df2)
function in R.
Given p
in [0, 1), returns the value of x for which the cumulative probability density of the central F distribution is p. That is, jStat.centralF.inv(p, df1, df2) = x
if and only if jStat.centralF.inv(x, df1, df2) = p
.
This function corresponds to the qf(p, df1, df2)
function in R.
Returns the mean of the (Central) F distribution.
Returns the mode of the (Central) F distribution.
Returns a random number whose distribution is the (Central) F distribution.
This function corresponds to the rf(n, df1, df2)
function in R.
Returns the variance of the (Central) F distribution.
Returns the value of x
in the pdf of the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of x
in the cdf of the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of p
in the inverse of the cdf for the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of the median for the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of the mode for the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns a random number whose distribution is the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of the variance for the Cauchy distribution with a location (median) of local
and scale factor of scale
.
Returns the value of x
in the pdf of the Chi Square distribution with dof
degrees of freedom.
Returns the value of x
in the cdf of the Chi Square distribution with dof
degrees of freedom.
Returns the value of x
in the inverse of the cdf for the Chi Square distribution with dof
degrees of freedom.
Returns the value of the mean for the Chi Square distribution with dof
degrees of freedom.
Returns the value of the median for the Chi Square distribution with dof
degrees of freedom.
Returns the value of the mode for the Chi Square distribution with dof
degrees of freedom.
Returns a random number whose distribution is the Chi Square distribution with dof
degrees of freedom.
Returns the value of the variance for the Chi Square distribution with dof
degrees of freedom.
Returns the value of x
in the pdf of the Exponential distribution with the parameter rate
(lambda).
Returns the value of x
in the cdf of the Exponential distribution with the parameter rate
(lambda).
Returns the value of p
in the inverse of the cdf for the Exponential distribution with the parameter rate
(lambda).
Returns the value of the mean for the Exponential distribution with the parameter rate
(lambda).
Returns the value of the median for the Exponential distribution with the parameter rate
(lambda)
Returns the value of the mode for the Exponential distribution with the parameter rate
(lambda).
Returns a random number whose distribution is the Exponential distribution with the parameter rate
(lambda).
Returns the value of the variance for the Exponential distribution with the parameter rate
(lambda).
Returns the value of x
in the pdf of the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
Returns the value of x
in the cdf of the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
This function is checked against R's pgamma
function.
Returns the value of p
in the inverse of the cdf for the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
This function is checked against R's qgamma
function.
Returns the value of the mean for the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
Returns the value of the mode for the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
Returns a random number whose distribution is the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
Returns the value of the variance for the Gamma distribution with the parameters shape
(k) and scale
(theta). Notice that if using the alpha beta convention, scale = 1/beta
.
Returns the value of x
in the pdf of the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of x
in the cdf of the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of p
in the inverse of the cdf for the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of the mean for the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of the mode for the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns a random number whose distribution is the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of the variance for the Inverse-Gamma distribution with parametres shape
(alpha) and scale
(beta).
Returns the value of x
in the pdf of the Kumaraswamy distribution with parameters a
and b
.
Returns the value of x
in the cdf of the Kumaraswamy distribution with parameters alpha
and beta
.
Returns the value of p
in the inverse of the pdf for the Kumaraswamy distribution with parametres alpha
and beta
.
This function corresponds to qkumar(p, alpha, beta)
in R's VGAM package.
Returns the value of the mean of the Kumaraswamy distribution with parameters alpha
and beta
.
Returns the value of the median of the Kumaraswamy distribution with parameters alpha
and beta
.
Returns the value of the mode of the Kumaraswamy distribution with parameters alpha
and beta
.
Returns the value of the variance of the Kumaraswamy distribution with parameters alpha
and beta
.
Returns the value of x
in the pdf of the Log-normal distribution with paramters mu
(mean) and sigma
(standard deviation).
Returns the value of x
in the cdf of the Log-normal distribution with paramters mu
(mean) and sigma
(standard deviation).
Returns the value of x
in the inverse of the cdf for the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns the value of the mean for the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns the value of the median for the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns the value of the mode for the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns a random number whose distribution is the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns the value of the variance for the Log-normal distribution with paramters mu
(mean of the Normal distribution) and sigma
(standard deviation of the Normal distribution).
Returns the value of x
in the pdf of the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of x
in the cdf of the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of p
in the inverse cdf for the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of the mean for the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of the median for the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of the mode for the Normal distribution with parameters mean
and std
(standard deviation).
Returns a random number whose distribution is the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of the variance for the Normal distribution with parameters mean
and std
(standard deviation).
Returns the value of x
in the pdf of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the inverse of the Pareto distribution with probability p
, scale
, shape
.
This coresponds to qpareto(p, scale, shape)
in R's VGAM package, and generally corresponds to the q
<dist> function pattern in R.
Returns the value of x
in the cdf of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the value of the mean of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the value of the median of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the value of the mode of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the value of the variance of the Pareto distribution with parameters scale
(x<sub>m</sub>) and shape
(alpha).
Returns the value of x
in the pdf of the Student's T distribution with dof
degrees of freedom.
Returns the value of x
in the cdf of the Student's T distribution with dof
degrees of freedom.
Returns the value of p
in the inverse of the cdf for the Student's T distribution with dof
degrees of freedom.
Returns the value of the mean of the Student's T distribution with dof
degrees of freedom.
Returns the value of the median of the Student's T distribution with dof
degrees of freedom.
Returns the value of the mode of the Student's T distribution with dof
degrees of freedom.
Returns a random number whose distribution is the Student's T distribution with dof
degrees of freedom.
Returns the value of the variance for the Student's T distribution with dof
degrees of freedom.
Returns the value of q in the cdf of the Studentized range distribution with nmeans
number of groups nmeans and dof
degrees of freedom.
Returns the value of p
in the inverse of the cdf for the Studentized range distribution with nmeans
number of groups and dof
degrees of freedom.
Only accurate to 4 decimal places.
Returns the value x
in the pdf for the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the value x
in the cdf for the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the value of x
in the inverse of the cdf for the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the value of the mean of the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the value of the median of the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the mode of the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns a random number whose distribution is the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the variance of the Weibull distribution with parameters scale
(lambda) and shape
(k).
Returns the value of x
in the pdf of the Uniform distribution from a
to b
.
Returns the value of x
in the cdf of the Uniform distribution from a
to b
.
Returns the inverse of the uniform.cdf
function; i.e. the value of x
for which uniform.cdf(x, a, b) == p
.
Returns the value of the mean of the Uniform distribution from a
to b
.
Returns the value of the median of the Uniform distribution from a
to b
.
Returns the value of the mode of the Uniform distribution from a
to b
.
Returns a random number whose distribution is the Uniform distribution from a
to b
.
Returns the variance of the Uniform distribution from a
to b
.
Returns the value of k
in the pdf of the Binomial distribution with parameters n
and p
.
Returns the value of k
in the cdf of the Binomial distribution with parameters n
and p
.
Returns the value of k
in the pdf of the Negative Binomial distribution with parameters n
and p
.
Returns the value of x
in the cdf of the Negative Binomial distribution with parameters n
and p
.
Returns the value of k
in the pdf of the Hypergeometric distribution with parameters N
(the population size), m
(the success rate), and n
(the number of draws).
Returns the value of x
in the cdf of the Hypergeometric distribution with parameters N
(the population size), m
(the success rate), and n
(the number of draws).
Returns the value of k
in the pdf of the Poisson distribution with parameter l
(lambda).
Returns the value of x
in the cdf of the Poisson distribution with parameter l
(lambda).
Returns a random number whose distribution is the Poisson distribution with rate parameter l (lamda)
Returns the value of x
in the pdf of the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of x
in the cdf of the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of the mean of the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of the median of the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of the mode of the Triangular distribution with the parameters a
, b
, and c
.
Returns a random number whose distribution is the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of the variance of the Triangular distribution with the parameters a
, b
, and c
.
Returns the value of x
in the pdf of the arcsine distribution from a
to b
.
Returns the value of x
in the cdf of the arcsine distribution from a
to b
.
Returns the inverse of the arcsine.cdf
function; i.e. the value of x
for which arcsine.cdf(x, a, b) == p
.
Returns the value of the mean of the arcsine distribution from a
to b
.
Returns the value of the median of the arcsine distribution from a
to b
.
Returns the value of the mode of the arcsine distribution from a
to b
.
Returns a random number whose distribution is the arcsine distribution from a
to b
.
Returns the variance of the Uniform distribution from a
to b
.
Evaluates the Beta function at (x,y)
.
Evaluates the log Beta function at (x,y)
.
Returns the continued fraction for the incomplete Beta function with parameters a and b modified by Lentz's method evaluated at x
.
Returns the inverse of the incomplete Beta function evaluated at (p,a,b)
.
Returns the incomplete Beta function evaluated at (x,a,b)
.
Returns the Gamma function evaluated at x
. This is sometimes called the 'complete' gamma function.
This function is tested against Mathematica's Gamma[x].
Returns the Log-Gamma function evaluated at x
.
Returns the lower incomplete gamma function evaluated at (a,x)
.
This function is usually written with a lower case greek gamma character, and is one of the two incomplete gamma functions.
This function is tested against Mathematica's Gamma[a, 0, x]. It is additionally tested against gammainc(a,x)'s 'lowinc' output from teh 'pracma' library for R.
Returns the lower regularized incomplete gamma function evaluated at (a,x)
.
It is defined as the quotient of the lower incomplete gamma function evaluated at (a, x) and the upper incomplete gamma function ('the gamma function') evaluated at (a).
This function is usually written as P(x, a); and is one of the two regularized gamma functions.
This function is tested against gammainc(x, a)'s 'reginc' output from the 'pracma' library for R. Note that R and jStat switch the order of operators for this function.
Returns the inverse of the lower regularized incomplete Gamma function evaluated at (p,a)
.
This function is the inverse of lowerRegularizedGamma(x, a).
Returns the natural log factorial of n
.
Returns the factorial of n
.
Returns the number of combinations of n
, m
.
Returns the number of permutations of n
, m
.
Returns the error function evaluated at x
.
Returns the complementary error function evaluated at x
.
Returns the inverse of the complementary error function evaluated at p
.
Returns a normal deviate (mean 0 and standard deviation 1).
Returns a Gamma deviate by the method of Marsaglia and Tsang.
Adds value to all entries.
jStat([[1,2,3]]).add( 2 ) === [[3,4,5]];
Subtracts all entries by value.
jStat([[4,5,6]]).subtract( 2 ) === [[2,3,4]];
Divides all entries by value.
jStat([[2,4,6]]).divide( 2 ) === [[1,2,3]];
Multiplies all entries by value.
jStat([[1,2,3]]).multiply( 2 ) === [[2,4,6]];
Takes dot product.
Raises all entries by value.
jStat([[1,2,3]]).pow( 2 ) === [[1,4,9]];
Exponentiates all entries.
jStat([[0,1]]).exp() === [[1, 2.718281828459045]]
Returns the natural logarithm of all entries.
jStat([[1, 2.718281828459045]]).log() === [[0,1]];
Returns the absolute values of all entries.
jStat([[1,-2,-3]]).abs() === [[1,2,3]];
Computes the norm of a vector. Note that if a matrix is passed, then the
first row of the matrix will be used as a vector for norm()
.
Computes the angle between two vectors. Note that if a matrix is passed, then
the first row of the matrix will be used as the vector for angle()
.
Adds arg
to all entries of arr
array.
Subtracts all entries of the arr
array by arg
.
Divides all entries of the arr
array by arg
.
Multiplies all entries of the arr
array by arg
.
Takes the dot product of the arr1
and arr2
arrays.
Takes the outer product of the A
and B
arrays.
outer([1,2,3],[4,5,6]) === [[4,5,6],[8,10,12],[12,15,18]]
Raises all entries of the arr
array to the power of arg
.
Exponentiates all entries in the arr
array.
Returns the natural logarithm of all entries in the arr
array
Returns the absolute values of all entries in the arr
array
Computes the norm of the arr
vector.
Computes the angle between the arr1
and arr2
vectors.
Augments matrix A
by matrix B
. Note that this method returns a plain matrix,
not a jStat object.
Calculates the determinant of matrix A
.
Returns the inverse of the matrix A
.
Performs Gaussian Elimination on matrix A
augmented by matrix B
.
Performs Gauss-Jordan Elimination on matrix A
augmented by matrix B
.
Perform the LU decomposition on matrix A
.
A
-> [L,U]
st.
A = LU
L
is lower triangular matrix.
U
is upper triangular matrix.
Performs the Cholesky decomposition on matrix A
.
A
-> T
st.
A = TT'
T
is lower triangular matrix.
Solves the linear system Ax = b
using the Gauss-Jacobi method with an initial guess of r
.
Solves the linear system Ax = b
using the Gauss-Seidel method with an initial guess of r
.
Solves the linear system Ax = b
using the sucessive over-relaxation method with an initial guess of r
and parameter w
(omega).
Performs the householder transformation on the matrix A
.
Performs the Cholesky decomposition on matrix A
.
A
-> [Q,R]
Q
is the orthogonal matrix.
R
is the upper triangular.
Solves least squard problem for Ax=b as QR decomposition way.
If b
is of the [[b1], [b2], [b3]]
form, the method will return an array of the [[x1], [x2], [x3]]
form solution.
Otherwise, if b
is of the [b1, b2, b3]
form, the method will return an array of the [x1,x2,x3]
form solution.
The test module includes methods that enact popular statistical tests. The tests that are implemented are Z tests, T tests, and F tests. Also included are methods for developing confidence intervals. Currently regression is not included but it should be included soon (once matrix inversion is fixed).
Returns the z-score of value
taking the jStat object as the observed
values. flag===true
denotes use of sample standard deviation.
Returns the p-value of value
taking the jStat object as the observed
values. sides
is an integer value 1 or 2 denoting a 1 or 2 sided z-test.
The test defaults to a 2 sided z-test if sides
is not specified. flag===true
denotes use of sample standard deviation.
Returns the t-score of value
taking the jStat object as the observed
values.
Returns the p-value of value
taking the jStat object as the observed
values. sides
is an integer value 1 or 2 denoting a 1 or 2 sided t-test.
The test defaults to a 2 sided t-test if sides
is not specified.
Returns the f-score of the ANOVA test on the arrays of the jStat object.
Returns the p-value of an ANOVA test on the arrays of the jStat object.
Returns the z-score of value
given the mean
mean and the sd
standard deviation
of the test.
Returns the z-score of value
given the data from array
. flag===true
denotes
use of the sample standard deviation.
Returns the p-value of a the z-test of value
given the mean
mean and sd
standard
deviation of the test. sides
is an integer value 1 or 2 denoting a
one or two sided z-test. If sides
is not specified the test defaults
to a two sided z-test.
Returns the p-value of the zscore
z-score. sides
is an integer value 1 or 2
denoting a one or two sided z-test. If sides
is not specified the test
defaults to a two sided z-test
Returns the p-value of value
given the data from array
. sides
is
an integer value 1 or 2 denoting a one or two sided z-test. If sides
is not specified the test defaults to a two sided z-test. flag===true
denotes the use of the sample standard deviation.
Returns the t-score of value
given the mean
mean, sd
standard deviation,
and the sample size n
.
Returns the t-score of value
given the data from array
.
Returns the p-value of value
given the mean
mean, sd
standard deviation,
and the sample size n
. sides
is an integer value 1 or 2 denoting
a one or two sided t-test. If sides
is not specified the test
defaults to a two sided t-test.
Returns the p-value of the tscore
t-score given the sample size n
. sides
is an integer value 1 or 2 denoting a one or two sided t-test.
If sides
is not specified the test defaults to a two sided t-test.
Returns the p-value of value
given the data in array
.
sides
is an integer value 1 or 2 denoting a one or two sided
t-test. If sides
is not specified the test defaults to a two
sided t-test.
Returns the f-score of an ANOVA on the arrays.
Returns the f-score of an ANOVA on the arrays.
Returns the p-value of the f-statistic from the ANOVA test on the arrays.
Returns the p-value for the fscore
f-score with a df1
numerator degrees
of freedom and a df2
denominator degrees of freedom.
Returns the q-score of a single pairwise comparison between arrays
of mean mean1
and mean2
, size n1
and n2
, and standard deviation (of
all vectors) sd
.
Same as above, but the means and sizes are calculated automatically from the arrays.
Returns the p-value of the q-score given the total sample size n
and k
number of populations.
Returns the p-value of a single pairwise comparison between arrays
of mean mean1
and mean2
, size n1
and n2
, and standard deviation (of
all vectors) sd
, where the total sample size is n
and the number of
populations is k
.
Same as above, but the means and sizes are calculated automatically from the arrays.
Performs the full Tukey's range test returning p-values for every
pairwise combination of the arrays in the format of
[[[index1, index2], pvalue], ...]
For example:
> jStat.tukeyhsd([[1, 2], [3, 4, 5], [6], [7, 8]])
[ [ [ 0, 1 ], 0.10745283896120883 ],
[ [ 0, 2 ], 0.04374051946838586 ],
[ [ 0, 3 ], 0.007850804224287633 ],
[ [ 1, 2 ], 0.32191548545694226 ],
[ [ 1, 3 ], 0.03802747415485819 ],
[ [ 2, 3 ], 0.5528665999257486 ] ]
Returns a 1-alpha confidence interval for value
given
a normal distribution with a standard deviation sd
and a
sample size n
Returns a 1-alpha confidence interval for value
given
a normal distribution in the data from array
.
Returns a 1-alpha confidence interval for value
given
the standard deviation sd
and the sample size n
.
Returns a 1-alpha confidence interval for value
given
the data from array
.
Returns the p-value for a 1-sided test for the difference
between two proportions. p1
is the sample proportion for
the first sample, whereas p2
is the sample proportion for
the second sample. Similiarly, n1
is the sample size of the
first sample and n2
is the sample size for the second sample.
Returns the p-value for a 2-sided test for the difference
between two proportions. p1
is the sample proportion for
the first sample, whereas p2
is the sample proportion for
the second sample. Similiarly, n1
is the sample size of the
first sample and n2
is the sample size for the second sample.