Proper Translation of equation to C#

Posted by Shykin on Stack Overflow See other posts from Stack Overflow or by Shykin
Published on 2012-06-02T04:26:31Z Indexed on 2012/06/02 4:40 UTC
Read the original article Hit count: 102

Filed under:
|

I am trying to replicate this equation: Slope(b) = (NSXY - (SX)(SY)) / (NSX2 - (SX)2) in C# but I'm getting the following issue:

If I make the average of X = 1 + 2 + 3 + 4 + 5 and the average Y = 5 + 4 + 3 + 2 + 1 it gives me a positive slope even though it is clearly counting down. If I place the same numbers into this calculator: http://www.easycalculation.com/statistics/regression.php

It gives me a negative slope in the linked calculator with the same data. I'm trying to narrow down the reasons so is the following a proper translation from equation to C# code:

Slope(b) = (NSXY - (SX)(SY)) / (NSX2 - (SX)2)

to

Slope (m) = ((x * avgX * avgY) - (avgX * avgY)) / ((x * Math.Pow(avgX, 2)) - Math.Pow(avgX, 2));

© Stack Overflow or respective owner

Related posts about c#

Related posts about statistics