rem: this.b = sumXdiffYdiff / sumXdiffsquared; this.a = this.Yavg - this.b * this.Xavg;  this.sigma = Math.sqrt( (sumYdiffsquared - this.b * sumXdiffYdiff) / (length - 2));  this.SE = this.sigma / Math.sqrt(sumXdiffsquared); 
add: this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X); this.a = (SUM_Y - this.b * SUM_X)/n;  this.Xavg = SUM_X/n; this.Yavg = SUM_Y/n;  var SUM_Ydiff2 = 0; var SUM_Xdiff2 = 0; var SUM_XdiffYdiff = 0;  for (i = 0; i < n; i++) { var Ydiff = Y[i] - this.Yavg; var Xdiff = X[i] - this.Xavg;  SUM_Ydiff2 += Ydiff * Ydiff; SUM_Xdiff2 += Xdiff * Xdiff; SUM_XdiffYdiff += Xdiff * Ydiff; }  var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2); var r2   = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) / ((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));  this.Syx = Math.sqrt(Syx2); this.r = Math.sqrt(r2);  
context: function BigO(data){  var order = 0;  var origLength = data.X.length;  while (data.X.length > 1)  {    var lr = new LinearRegression(data);    order++;    if (lr.SE < 0.01)    {      break;    }    data = dataDeriv(data);  }   if (order == origLength - 1)  {    order = Number.POSITIVE_INFINITY;  }  return order;  function LinearRegression(data)    {      // http://www.bearcave.com/misl/misl_tech/wavelets/stat/      /*        X0,X1...; Y0,Y1,...        b = sum( (Xi - Xavg)(Yi - Yavg) ) / sum ( (Xi - Xavg)*(Xi - Xavg) )        a = Yavg - b * Xavg        stddev*stddev = (sum( (Yi - Yavg) * (Yi - Yavg) ) -         b * sum( (Xi - Xavg)*(Yi - Yavg) ) ) /        sum ( (Xi - Xavg) * (Xi - Xavg) )      */      var i;      if (data.X.length != data.Y.length)      {        throw 'LinearRegression: data point length mismatch';      }      if (data.X.length < 2)      {        throw 'LinearRegression: data point length < 2';      }      var length = data.X.length;      var X = data.X;      var Y = data.Y;      this.Xavg = 0;      this.Yavg = 0;      for (i = 0; i < length; i++)      {        this.Xavg += X[i];        this.Yavg += Y[i];      }      this.Xavg /= length;      this.Yavg /= length;      var sumXdiffYdiff = 0;      var sumXdiffsquared = 0;      var sumYdiffsquared = 0;      for (i = 0; i < length; i++)      {        var xDiff = (X[i] - this.Xavg);        var yDiff = (Y[i] - this.Yavg);        sumXdiffYdiff   += xDiff * yDiff;        sumXdiffsquared += xDiff * xDiff;         sumYdiffsquared += yDiff * yDiff;      }      this.b = sumXdiffYdiff / sumXdiffsquared;      this.a = this.Yavg - this.b * this.Xavg;      // standard deviation of regression      this.sigma = Math.sqrt( (sumYdiffsquared - this.b * sumXdiffYdiff) /                               (length - 2));      // standard error in b      this.SE = this.sigma / Math.sqrt(sumXdiffsquared);    }  function dataDeriv(data)    {      if (data.X.length != data.Y.length)      {        throw 'length mismatch';      }      var length = data.X.length;      if (length < 2)      {        throw 'length ' + length + ' must be >= 2';      }      var X = data.X;      var Y = data.Y;      var deriv = {X: [], Y: [] };      for (var i = 0; i < length - 1; i++)      {        deriv.X[i] = (X[i] + X[i+1])/2;        deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);      }        return deriv;    }}
meta: 10234	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/10234/0c224a23a1a1941a55f278c5b505f75c385066c0/shell.js/buggy/js/tests/js1_5/shell.js