Linear Regression PHP Class
This PHP 5 class accepts an array of data as input, performs linear regression analysis and returns the trend line. The result is the same as in Excel (Tools/Data Analysis/Regression)
Ad Serving, Ad Management, Online Advertising, Entrepreneurship, Web Development, High Availability, Load Balancing, PHP, MySQL, AJAX
This PHP 5 class accepts an array of data as input, performs linear regression analysis and returns the trend line. The result is the same as in Excel (Tools/Data Analysis/Regression)
6 Comments:
Hey, Your code rocks except for Line 21, where it says $vSumXY += $x*$x; instead of $vSumXX += $x*$x; . Please correct it, it took me quite a lot of time to figure out, why the results were wrong.
Thanks anyway, I really appreciated it :)
Correction has been made. It's weird how I have it correct in the codebase but somehow pasted it incorrectly to the blog. :) Thanks Andras.
So where does the data go? Wheer and how do you enter data streams in to this code to run it?
For those who are interested, I have compared the values of slope and Y-intercept given by this Class with those given by Excel. They produce exactly equivalent responses, at least out to 10 decimal places. Nice work.
I would love to see an example of how this class works...
Thank you very much for the code. But I would like to know how the functions will be called. It would be great if you provide some example.
Thank you
^Amy
Post a Comment
<< Home