Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MultipleLinearRegression | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
getRegression | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getSlope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getElasticity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package TBD |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Math\Statistic\Forecast\Regression; |
16 | |
17 | use phpOMS\Math\Matrix\Matrix; |
18 | |
19 | /** |
20 | * Regression class. |
21 | * |
22 | * @package phpOMS\Math\Statistic\Forecast\Regression |
23 | * @license OMS License 2.0 |
24 | * @link https://jingga.app |
25 | * @since 1.0.0 |
26 | */ |
27 | final class MultipleLinearRegression extends RegressionAbstract |
28 | { |
29 | /** |
30 | * Get linear regression based on scatter plot. |
31 | * |
32 | * @latex y = b_{0} + b_{1} \cdot x |
33 | * |
34 | * @param array<array<int|float>> $x Obersved x values |
35 | * @param array<array<int|float>> $y Observed y values |
36 | * |
37 | * @return array [b0 => ?, b1 => ?] |
38 | * |
39 | * @since 1.0.0 |
40 | */ |
41 | public static function getRegression(array $x, array $y) : array |
42 | { |
43 | $X = new Matrix(\count($x), \count($x[0])); |
44 | $X->setMatrix($x); |
45 | $XT = $X->transpose(); |
46 | |
47 | $Y = new Matrix(\count($y)); |
48 | $Y->setMatrix($y); |
49 | |
50 | return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix(); |
51 | } |
52 | |
53 | /** |
54 | * {@inheritdoc} |
55 | */ |
56 | public static function getSlope(float $b1, float $y, float $x) : float |
57 | { |
58 | return 0.0; |
59 | } |
60 | |
61 | /** |
62 | * {@inheritdoc} |
63 | */ |
64 | public static function getElasticity(float $b1, float $y, float $x) : float |
65 | { |
66 | return 0.0; |
67 | } |
68 | } |