Forecast formula from Excel in Javascript -


i'm trying make forecast function in javascript based on code excel, explained @ https://support.office.com/en-us/article/forecast-function-50ca49c9-7b40-4892-94e4-7ad38bbeda99

but don't understand x trait on top (also y) formula , don't know how translate in javascript.

can me please?

thank you.

x trait on top mean of x (i.e. average of xs). same y. if x values 20,28,31,38,40 x trait on top 31.4

function forecast(x, ky, kx){    var i=0, nr=0, dr=0,ax=0,ay=0,a=0,b=0;    function average(ar) {           var r=0;       (i=0;i<ar.length;i++){          r = r+ar[i];       }       return r/ar.length;    }    ax=average(kx);    ay=average(ky);    (i=0;i<kx.length;i++){       nr = nr + ((kx[i]-ax) * (ky[i]-ay));       dr = dr + ((kx[i]-ax)*(kx[i]-ax))    }   b=nr/dr;   a=ay-b*ax;   return (a+b*x); } 

the above script gives forecast without error handling.

you can call using below method

forecast(30,[6,7,9,15,21],[20,28,31,38,40]); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -