Search code examples
javascriptexcelexcel-formulatrendline

How to calculate r squared value in JavaScript


I am working with trendlines in charts. And I need to display R squared value in it as displayed in excel charts with trendline.

enter image description here

I came across many links, but cant find a definite answer.

So please guide me with a step by step procedure or any links to achieve this.

Thanks


Solution

  • Linear regression (or Bravais-Pearson index) is a mathematical formula Excel can calculate, but JavaScript can't.

    Look at this article on how to calculate it:

    http://trentrichardson.com/2010/04/06/compute-linear-regressions-in-javascript/