title: Linear Regression in Javascript
body: <p>I want to do Least Squares Fitting in Javascript in a web browser.</p>
  
  <p>Currently users enter data point information using HTML text inputs and then I grab that data with jQuery and graph it with <a href="http://code.google.com/p/flot/">Flot</a>.</p>
  
  <p>After the user had entered in their data points I would like to present them with a "line of best fit". I imagine I would calculate the linear, polynomial, exponential and logarithmic equations and then choose the one with the highest <code>R^2</code> value.</p>
  
  <p>I can't seem to find any libraries that will help me to do this though. I stumbled upon <a href="http://www.jstat.org/">jStat</a>, but it is completely missing documentation (as far as I can find) and after digging through the the source code it doesn't seem to have any linear regression functionality built in--I'm basing this purely on function names however.</p>
  
  <p>Does anyone know any Javascript libraries that offer simple regression analysis?</p>
  
  <hr>
  
  <p>The hope would be that I could use the library like so...</p>
  
  <p>If I had some set of scatter points in an array <code>var points = [[3,4],[15,45],...[23,78]]</code>, I would be able to hand that to some function like <code>lin_reg(points)</code> and it would return something like <code>[7.12,3]</code> if the linear equation was <code>y = 7.12 x + 3</code>.</p>