mnshankar / linear-regression
PHP package for computation of simple linear regression parameters
Installs: 20 279
Dependents: 0
Suggesters: 0
Security: 0
Stars: 23
Watchers: 5
Forks: 10
Open Issues: 3
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: 4.5.0
This package is not auto-updated.
Last update: 2025-02-15 19:10:15 UTC
README
Simple Linear Regression
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.
Installation
Add the LinearRegression package as a dependency to your composer.json file:
{ "require": { "mnshankar/linear-regression": "1.0.*" } }
Using the tool
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.