# tmcw/simple-statistics

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Improve documentation, remove trailing whitespace

commit 0fd38db8f699c76e1417e07aea16475ae7faf195 1 parent ea4d09c
authored
Showing with 18 additions and 7 deletions.
1. +8 −4 docs/simple_statistics.html
2. +10 −3 src/simple_statistics.js
12 docs/simple_statistics.html
 @@ -296,7 +296,9 @@ } else {

Finally, in the simple case of an integer value with an odd-length list, return the sample value at the index.

return sorted[idx];
}
-    };

Compute the matrices required for Jenks breaks. These matrices + };

Compute Matrices for Jenks

+ +

Compute the matrices required for Jenks breaks. These matrices can be used for any classing of data with classes <= n_classes

ss.jenksMatrices = function(data, n_classes) {

in the original implementation, these matrices are referred to as LC and OP

@@ -323,8 +325,8 @@ } for (var l = 2; l < data.length + 1; l++) {

SZ originally. this is the sum of the values seen thus -far when calculating variance.

var sum = 0,

ZSQ originally. the sum of squares of values seen -thus far

sum_squares = 0,

WT originally. This is the number of

w = 0,

IV originally

i4 = 0;

in several instances, you could say Math.pow(x, 2) +far when calculating variance.

var sum = 0,

ZSQ originally. the sum of squares of values seen +thus far

sum_squares = 0,

WT originally. This is the number of

w = 0,

IV originally

i4 = 0;

in several instances, you could say Math.pow(x, 2) instead of x * x, but this is slower in some browsers introduces an unnecessary concept.

for (var m = 1; m < l + 1; m++) {

III originally

var lower_class_limit = l - m + 1,
val = data[lower_class_limit - 1];

here we're estimating variance for each potential classing @@ -358,7 +360,9 @@ lower_class_limits: lower_class_limits, variance_combinations: variance_combinations }; - };

the second part of the jenks recipe: take the calculated matrices + };

Pull Breaks Values for Jenks

+ +

the second part of the jenks recipe: take the calculated matrices and derive an array of n breaks.

ss.jenksBreaks = function(data, lower_class_limits, n_classes) {

var k = data.length - 1,
13 src/simple_statistics.js
 @@ -545,6 +545,8 @@ } }; + // ## Compute Matrices for Jenks + // // Compute the matrices required for Jenks breaks. These matrices // can be used for any classing of data with `classes <= n_classes` ss.jenksMatrices = function(data, n_classes) { @@ -564,6 +566,9 @@ // Initialize and fill each matrix with zeroes for (i = 0; i < data.length + 1; i++) { var tmp1 = [], tmp2 = []; + // despite these arrays having the same values, we need + // to keep them separate so that changing one does not change + // the other for (j = 0; j < n_classes + 1; j++) { tmp1.push(0); tmp2.push(0); @@ -586,11 +591,11 @@ // `SZ` originally. this is the sum of the values seen thus // far when calculating variance. - var sum = 0, + var sum = 0, // `ZSQ` originally. the sum of squares of values seen // thus far sum_squares = 0, - // `WT` originally. This is the number of + // `WT` originally. This is the number of w = 0, // `IV` originally i4 = 0; @@ -624,7 +629,7 @@ for (j = 2; j < n_classes + 1; j++) { // if adding this element to an existing class // will increase its variance beyond the limit, break - // the class at this point, setting the lower_class_limit + // the class at this point, setting the `lower_class_limit` // at this point. if (variance_combinations[l][j] >= (variance + variance_combinations[i4][j - 1])) { @@ -649,6 +654,8 @@ }; }; + // ## Pull Breaks Values for Jenks + // // the second part of the jenks recipe: take the calculated matrices // and derive an array of n breaks. ss.jenksBreaks = function(data, lower_class_limits, n_classes) {