PHPackages                             luminsports/linear-regression - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. luminsports/linear-regression

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

luminsports/linear-regression
=============================

Linear regression

1.3.2(1mo ago)255MITPHPPHP ^8.1CI passing

Since Aug 18Pushed 1mo agoCompare

[ Source](https://github.com/luminsports/php-linear-regression)[ Packagist](https://packagist.org/packages/luminsports/linear-regression)[ RSS](/packages/luminsports-linear-regression/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (12)Versions (10)Used By (0)

PHP Linear Regression
=====================

[](#php-linear-regression)

[![Code Style](https://github.com/luminsports/least-squares-regression/actions/workflows/php-cs-fixer.yml/badge.svg?branch=main)](https://github.com/luminsports/least-squares-regression/actions/workflows/php-cs-fixer.yml)[![PHPStan](https://github.com/luminsports/least-squares-regression/actions/workflows/phpstan.yml/badge.svg?branch=main)](https://github.com/luminsports/least-squares-regression/actions/workflows/phpstan.yml)[![Tests](https://github.com/luminsports/least-squares-regression/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/luminsports/least-squares-regression/actions/workflows/tests.yml)

A small PHP library for fitting a straight line to paired data with ordinary least squares. It uses `brick/math` and BCMath for precise intermediate arithmetic and provides predictions, residuals, cumulative residuals, regression-line points, and the coefficient of determination.

Originally forked from [davebarnwell/ml-regression-least-squares](https://github.com/davebarnwell/ml-regression-least-squares).

Requirements
------------

[](#requirements)

- PHP 8.1 or later
- BCMath extension

Installation
------------

[](#installation)

```
composer require luminsports/linear-regression
```

Usage
-----

[](#usage)

```
use LuminSports\LinearRegression\LeastSquares;

$targets = [1, 2, 3, 4];
$observations = [2.1, 4.0, 6.2, 7.9];

$regression = new LeastSquares($targets, $observations);

$slope = $regression->getSlope();
$intercept = $regression->getIntercept();
$rSquared = $regression->getRSquared();

$predictedObservation = $regression->predictY(5);
$predictedTarget = $regression->predictX(10);

$residuals = $regression->getDifferencesFromRegressionLine();
$cumulativeResiduals = $regression->getCumulativeSumOfDifferencesFromRegressionLine();
$linePoints = $regression->getRegressionLinePoints();
```

The X series represents target or independent values; the Y series represents observed or dependent values. Both arrays must contain the same number of elements or `SeriesCountMismatch` is thrown.

The optional constructor precision controls division and rounding:

```
$regression = new LeastSquares($targets, $observations, precision: 12);
$regression->setPrecision(10);
```

Development
-----------

[](#development)

```
composer install
composer test
composer phpstan
composer check-style
```

Generate an HTML coverage report with `composer coverage`. Apply formatting intentionally with `composer fix-style`.

Contributing and Security
-------------------------

[](#contributing-and-security)

Keep changes focused on the numerical library, preserve supported PHP compatibility, and add regression tests for calculation changes. See the [Lumin Sports contributing guide](https://github.com/luminsports/.github/blob/main/CONTRIBUTING.md).

Report security vulnerabilities privately through the repository security policy; do not disclose sensitive details in a public issue.

License
-------

[](#license)

Released under the MIT License. See [LICENSE.md](LICENSE.md) and [COPYRIGHT](COPYRIGHT).

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 52.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Recently: every ~129 days

Total

8

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e55216f06906e0bdee2b78e0b2c0c9d5009a4bbab212341d04e3584ba8d864c?d=identicon)[ryzr](/maintainers/ryzr)

---

Top Contributors

[![davebarnwell](https://avatars.githubusercontent.com/u/97731?v=4)](https://github.com/davebarnwell "davebarnwell (20 commits)")[![ryzr](https://avatars.githubusercontent.com/u/9389421?v=4)](https://github.com/ryzr "ryzr (17 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

php

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/luminsports-linear-regression/health.svg)

```
[![Health](https://phpackages.com/badges/luminsports-linear-regression/health.svg)](https://phpackages.com/packages/luminsports-linear-regression)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.4k](/packages/laravel-framework)[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k761.3M4.3k](/packages/ramsey-uuid)[brick/money

Money and currency library

1.9k43.2M194](/packages/brick-money)[illuminate/database

The Illuminate Database package.

2.8k55.8M13.1k](/packages/illuminate-database)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378637.6k125](/packages/flow-php-etl)[azuracast/azuracast

The AzuraCast self-hosted web radio station management suite.

4.0k27.9k](/packages/azuracast-azuracast)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
