Skip to content

PHP package for computation of simple linear regression parameters

License

Notifications You must be signed in to change notification settings

bryguy/linear-regression

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

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.

About

PHP package for computation of simple linear regression parameters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%