build/modelscript.umd.js
function coefficientOfCorrelation(actuals = [], estimates = []) {
              if (actuals.length !== estimates.length) throw new RangeError('arrays must have the same length');
              const sumX = sum(actuals);
              const sumY = sum(estimates);
              const sumProdXY = actuals.reduce((result, val, index) => { 
                result = result + (actuals[ index ] * estimates[ index ]);
                return result;
              }, 0);
              const sumXSquared = actuals.reduce((result, val) => { 
                result = result + (val * val);
                return result;
              }, 0);
              const sumYSquared = estimates.reduce((result, val) => { 
                result = result + (val * val);
                return result;
              }, 0);
              const N = actuals.length;
              const R = (
                (N * sumProdXY - sumX * sumY) /
                Math.sqrt(
                  (N * sumXSquared - Math.pow(sumX, 2)) * (N * sumYSquared - Math.pow(sumY, 2))
                )
              );
              return R;
            }
function coefficientOfCorrelation(actuals = [], estimates = []) {
              if (actuals.length !== estimates.length) throw new RangeError('arrays must have the same length');
              const sumX = sum(actuals);
              const sumY = sum(estimates);
              const sumProdXY = actuals.reduce((result, val, index) => { 
                result = result + (actuals[ index ] * estimates[ index ]);
                return result;
              }, 0);
              const sumXSquared = actuals.reduce((result, val) => { 
                result = result + (val * val);
                return result;
              }, 0);
              const sumYSquared = estimates.reduce((result, val) => { 
                result = result + (val * val);
                return result;
              }, 0);
              const N = actuals.length;
              const R = (
                (N * sumProdXY - sumX * sumY) /
                Math.sqrt(
                  (N * sumXSquared - Math.pow(sumX, 2)) * (N * sumYSquared - Math.pow(sumY, 2))
                )
              );
              return R;
            }
function coefficientOfCorrelation ( actuals = [ ] , estimates = [ ] ) { if ( actuals . length !== estimates . length ) throw new RangeError ( 'arrays must have the same length' ) ; const sumX = sum ( actuals ) ; const sumY = sum ( estimates ) ; const sumProdXY = actuals . reduce ( ( result , val , index ) => { result = result + ( actuals [ index ] * estimates [ index ] ) ; return result ; } , 0 ) ; const sumXSquared = actuals . reduce ( ( result , val ) => { result = result + ( val * val ) ; return result ; } , 0 ) ; const sumYSquared = estimates . reduce ( ( result , val ) => { result = result + ( val * val ) ; return result ; } , 0 ) ; const N = actuals . length ; const R = ( ( N * sumProdXY - sumX * sumY ) / Math . sqrt ( ( N * sumXSquared - Math . pow ( sumX , 2 ) ) * ( N * sumYSquared - Math . pow ( sumY , 2 ) ) ) ) ; return R ; }
The coefficent of Correlation is given by R decides how well the given data fits a line or a curve.
@example
const actuals = [ 39, 42, 67, 76, ];
const estimates = [ 44, 40, 60, 84, ];
const R = ms.util.coefficientOfCorrelation(actuals, estimates);
R.toFixed(4) // => 0.9408
@memberOf util
@see {@link https://calculator.tutorvista.com/r-squared-calculator.html}
@param {Number[]} actuals - numerical samples
@param {Number[]} estimates - estimates values
@returns {Number} R
The coefficent of Correlation is given by R decides how well the given data fits a line or a curve .