This package is used to compute simple linear regression parameters using PHP. It can be used to closely mimic the output of excel regression computation add-in. For a good how-to and intro if you are unfamiliar with this feature see Excel-easy's regression example.
Add the LinearRegression package as a dependency to your composer.json file:
{
"require": {
"mnshankar/linear-regression": "1.0.*"
}
}
The unit tests (in the tests folder) contain a wealth of information regarding the API. Basically, you load up the X and Y columns (from arrays or a CSV) and run the compute() method to generate all the regression parameters :-)
$reg = new \mnshankar\LinearRegression\Regression();
$reg->setX($this->getXForTesting());
$reg->setY($this->getYForTesting());
$reg->compute();
Note: To account for the intercept, the first element of all X arrays is forced to be 1.
Please refer to the Excel workbook named "Regression_Verification.xlsx" in the tests folder. The worksheet named "Calculated Values" contains all parameters generated by the excel add-in using data in the worksheet named "Raw Data".
The unit tests for regression computation tests/RegressionTest.php
verifies that this
same data is generated by the PHP package.