# simple-statistics/simple-statistics

Update docs for code style

1 parent 34a6e14 commit b8fcc3ac6e1ee9ffae439318cd21d024b6d53413 tmcw committed Feb 7, 2013
Showing with 7 additions and 6 deletions.
1. +7 −6 docs/simple_statistics.html
 @@ -215,14 +215,15 @@ }

the covariance is weighted by the length of the datasets.

return sum / (x.length - 1);
};

correlation

-

Gets a measure of how correlated two datasets are, between -1 and 1

ss.sample_correlation = function(x, y){
-        var cov = ss.sample_covariance(x, y);
-        var xstd = ss.sample_standard_deviation(x);
-        var ystd = ss.sample_standard_deviation(y);
+

Gets a measure of how correlated two datasets are, between -1 and 1

ss.sample_correlation = function(x, y) {
+        var cov = ss.sample_covariance(x, y),
+            xstd = ss.sample_standard_deviation(x),
+            ystd = ss.sample_standard_deviation(y);

-        if (cov === null || xstd === null || ystd === null){
-          return null;
+        if (cov === null || xstd === null || ystd === null) {
+            return null;
}
+
return cov / xstd / ystd;
};

median

ss.median = function(x) {

The median of an empty list is null

if (x.length === 0) return null;

Sorting the array makes it easy to find the center, but use .slice() to ensure the original array x is not modified

var sorted = x.slice().sort(function (a, b) { return a - b; });

If the length of the list is odd, it's the central number

if (sorted.length % 2 === 1) {