streaming

All members of streaming are higher order functions. Each function returns a Stream.

Methods

covariance

covariance() → {Stream}

Covariance is computed incrementally with arrival of each pair of x and y values from a stream of data.

The compute() requires two numeric arguments x and y.

The result() returns an object containing sample covariance cov, along with meanX, meanY and size of data i.e. number of x & y pairs. It also contains population covariance covp.

Example
var covariance = cov();
covariance.compute( 10, 80 );
covariance.compute( 15, 75 );
covariance.compute( 16, 65 );
covariance.compute( 18, 50 );
covariance.compute( 21, 45 );
covariance.compute( 30, 30 );
covariance.compute( 36, 18 );
covariance.compute( 40, 9 );
covariance.result();
// returns { size: 8,
//   meanX: 23.25,
//   meanY: 46.5,
//   cov: -275.8571,
//   covp: -241.375
// }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

freqTable

freqTable() → {Stream}

Frequency table is built incrementally with arrival of each value from the stream of data.

The build() requires a single argument, which could be either a string or numeric value.

The result() returns an object containing the frequency table sorted in descending order of category frequency, along with table size, sum of frequencies, x2 — chi-squared statistic, df — degree of freedom, and the entropy.

The x2 along with the df can be used to test the hypothesis, "the distribution is uniform". The percentage in table represents %age of a category share in the sum; and expected count assuming uniform distribution.

Example
var ft = freqTable();
ft.build( 'Tea' );
ft.build( 'Tea' );
ft.build( 'Tea' );
ft.build( 'Pepsi' );
ft.build( 'Pepsi' );
ft.build( 'Gin' );
ft.build( 'Coke' );
ft.build( 'Coke' );
ft.value();
// returns { Tea: 3, Pepsi: 2, Gin: 1, Coke: 2 }
ft.result();
// returns {
//   table: [
//     { category: 'Tea', observed: 3, percentage: 37.5, expected: 2 },
//     { category: 'Pepsi', observed: 2, percentage: 25, expected: 2 },
//     { category: 'Coke', observed: 2, percentage: 25, expected: 2 },
//     { category: 'Gin', observed: 1, percentage: 12.5, expected: 2 }
//   ],
//   size: 4,
//   sum: 8,
//   x2: 1,
//   df: 3,
//   entropy: 1.9056
// }
Returns

Object containing methods such as build(), result() & reset().

Type
Stream

max

max() → {Stream}

Maximum value is determined incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument.

The result() returns an object containing max.

Example
var maximum = max();
maximum.compute( 3 );
maximum.compute( 6 );
maximum.value();
// returns 6
maximum.result();
// returns { max: 6 }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

mean

mean() → {Stream}

Mean is computed incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument. The computations are inspired by the method proposed by B. P. Welford.

The result() returns an object containing sample mean along with size of data.

Example
var avg = mean();
avg.compute( 2 );
avg.compute( 3 );
avg.compute( 5 );
avg.compute( 7 );
avg.value();
// returns 4.25
avg.result();
// returns { n: 4, mean: 4.25 }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

min

min() → {Stream}

Minimum value is determined incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument.

The result() returns an object containing min.

Example
var minimum = min();
minimum.compute( 3 );
minimum.compute( 6 );
minimum.value();
// returns 3
minimum.result();
// returns { min: 3 }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

simpleLinearRegression

simpleLinearRegression() → {Stream}

Linear Regression is determined incrementally with arrival of each pair of x and y values from the data stream.

The compute() requires two numeric arguments viz. x — independant variable and y — dependant variable.

The result() returns an object containing slope, intercept, r, r2, se along with the size of data i.e. number of x & y pairs. It has an alias value().

In case of any error such as no input data or zero variance, correlation object will be an empty one.

Example
var regression = simpleLinearRegression();
regression.compute( 10, 80 );
regression.compute( 15, 75 );
regression.compute( 16, 65 );
regression.compute( 18, 50 );
regression.compute( 21, 45 );
regression.compute( 30, 30 );
regression.compute( 36, 18 );
regression.compute( 40, 9 );
regression.result();
// returns { slope: -2.3621,
//   intercept: 101.4188,
//   r: -0.9766,
//   r2: 0.9537,
//   se: 5.624,
//   size: 8
// }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

stdev

stdev() → {Stream}

Standard Deviation is computed incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument. The computations are inspired by the method proposed by B. P. Welford.

The result() returns returns an object containing sample stdev and variance, along with mean, size of data; it also contains population standard deviation and variance as stdevp and variancep.

Example
var sd = stdev();
sd.compute( 2 );
sd.compute( 3 );
sd.compute( 5 );
sd.compute( 7 );
sd.value();
// returns 2.2174
sd.result();
// returns { size: 4, mean: 4.25,
//   variance:  4.9167,
//   stdev: 2.2174,
//   variancep: 3.6875,
//   stdevp: 1.9203
// }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

sum

sum() → {Stream}

Sum is computed incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument.

The result() returns an object containing sum.

Example
var addition = sum();
addition.compute( 1 );
addition.compute( 10e+100 );
addition.compute( 1 );
addition.compute( -10e+100 );
addition.value();
// returns 2
addition.result();
// returns { sum: 2 }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream

summary

summary() → {Stream}

Summary Statistics is computed incrementally with arrival of each value from the data stream.

The compute() requires a single numeric value as argument. The computations are inspired by the method proposed by B. P. Welford.

The result() returns an object containing size, min, mean, max, sample stdev along with sample variance of data; it also contains population standard deviation and variance as stdevp and variancep.

Example
var ss = summary();
ss.compute( 2 );
ss.compute( 3 );
ss.compute( 5 );
ss.compute( 7 );
ss.result();
// returns { size: 4, min: 2, mean: 4.25, max: 7,
//   variance: 4.9167,
//   stdev: 2.2174,
//   3.6875,
//   stdevp: 1.9203
// }
Returns

Object containing methods such as compute(), result() & reset().

Type
Stream