PHP code example of luminsports / linear-regression

1. Go to this page and download the library: Download luminsports/linear-regression library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luminsports / linear-regression example snippets


$x = [...]; // target values
$y = [...]; // observation values

$linearRegression = new \LuminSports\LinearRegression\LeastSquares($x, $y);

$slope = $linearRegression->getSlope();
$yIntercept = $linearRegression->getIntercept();
    
// return array of differences of y values from the regression line
$differences = $linearRegression->getDifferencesFromRegressionLine();

// return array of cumulative sum of the differences of y values from the regression line
$cumulativeSum = $linearRegression->getCumulativeSumOfDifferencesFromRegressionLine();

// return array of Point objects giving the x,y values of the regression line
// for current data
$regressionLine = $linearRegression->getRegressionLinePoints();

$regressionLine[0]->getX();
$regressionLine[0]->getY();

$predictedX = $linearRegression->predictX($anObservationValue);

$predictedY = $linearRegression->predictY($aTargetValue);

$rSquared = $linearRegression->getRSquared(); // Regression fit; 1 = perfect fit 0 = no fit