Skip to content

Commit

Permalink
Merge pull request #35 from IDisposable/patch-1
Browse files Browse the repository at this point in the history
Move mean calculation out of loop
  • Loading branch information
simogeo authored Oct 31, 2016
2 parents 42639e0 + 5f3c060 commit 7dddc89
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/geostats.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ var geostats = function(a) {

if (this.stat_variance == null) {

var tmp = 0;
var tmp = 0, serie_mean = this.mean();
for (var i = 0; i < this.pop(); i++) {
tmp += Math.pow( (this.serie[i] - this.mean()), 2 );
tmp += Math.pow( (this.serie[i] - serie_mean), 2 );
}

this.stat_variance = tmp / this.pop();
this.stat_variance = tmp / this.pop();

if(round == true) {
this.stat_variance = Math.round(this.stat_variance * Math.pow(10,this.roundlength) )/ Math.pow(10,this.roundlength);
Expand Down

0 comments on commit 7dddc89

Please sign in to comment.