unit test fixes, phpstan fixes, phpcs fixes

This commit is contained in:
Dennis Eichhorn 2020-05-06 21:12:20 +02:00
parent 5e04905b8e
commit 7be395233c
4 changed files with 60 additions and 11 deletions

View File

@ -142,7 +142,7 @@ final class Metrics
*/
public static function calclateMailingSuccess(float $discountRate, array $purchaseProbability, array $payoffs) : Matrix
{
$count = \count($purchaseProbability);
$count = \count($purchaseProbability);
$profit = new Matrix($count, $count);
$G = Vector::fromArray($payoffs);
@ -233,8 +233,8 @@ final class Metrics
$count = \count($purchaseProbability);
for ($i = 0; $i < $count; ++$i) {
$matrix[$i] = [];
$matrix[$i][0] = $purchaseProbability[$i];
$matrix[$i] = [];
$matrix[$i][0] = $purchaseProbability[$i];
$matrix[$i][$i + 1] = 1 - $purchaseProbability[$i];
}

View File

@ -188,10 +188,10 @@ final class TDistribution
$sum = 0.0;
if ($degrees % 2 === 1) {
$i = 3;
$i = 3;
$term = $cos;
} else {
$i = 2;
$i = 2;
$term = 1;
}

View File

@ -41,20 +41,61 @@ final class ZTest
/**
* Test hypthesis.
*
* @param float $dataset Value observed
* @param float $expected Expected value
* @param float $total Observed dataset size
* @param float $significance Significance
*
* @return bool
*
* @since 1.0.0
*/
public static function testHypothesis(float $dataset, float $expected, float $total, float $significance = 0.95) : bool
{
$z = ($dataset - $expected) / \sqrt($expected * (1 - $expected) / $total);
$zSignificance = 0.0;
foreach (self::TABLE as $key => $value) {
if ($significance === $value) {
$zSignificance = (float) $key;
}
}
return $z > -$key && $z < $key;
}
/**
* Z-TEST.
*
* @param float $value Value to test
* @param array $data Data
* @param float $alpha Alpha / Observed dataset size
* @param null|float $sigma Sigma / Significance
*
* @return float
*
* @since 1.0.0
*/
public static function testHypothesis(array $data, float $alpha, float $sigma = null) : float
public static function zTesting(float $value, array $data, float $sigma = null) : float
{
if ($sigma === null) {
return MeasureOfDispersion::standardDeviationSample($data);
}
$sigma ??= MeasureOfDispersion::standardDeviationSample($data);
return 1 - NormalDistribution::dist((Average::arithmeticMean($data) - $alpha) / ($sigma / \sqrt(\count($data))), 0.0, 1.0, true);
return 1 - NormalDistribution::dist((Average::arithmeticMean($data) - $value) / ($sigma / \sqrt(\count($data))), 0.0, 1.0, true);
}
/**
* Z-TEST.
*
* @param float $value Value to test
* @param float $mean Mean
* @param int $dataSize Data size
* @param float $sigma Sigma / Significance
*
* @return float
*
* @since 1.0.0
*/
public static function zTestingValues(float $value, float $mean, int $dataSize, float $sigma) : float
{
return 1 - NormalDistribution::dist(($mean - $value) / ($sigma / \sqrt($dataSize)), 0.0, 1.0, true);
}
}

View File

@ -31,4 +31,12 @@ class ZTestTest extends \PHPUnit\Framework\TestCase
self::assertFalse(ZTest::testHypothesis($observed, $expected, $total, $a));
}
// https://support.microsoft.com/en-us/office/z-test-function-d633d5a3-2031-4614-a016-92180ad82bee?ui=en-us&rs=en-us&ad=us
public function testZTest() : void
{
//self::assertEqualsWithDelta(0.090574, ZTest::zTest(4, [3, 6, 7, 8, 6, 5, 4, 2, 1, 9]), 0.001);
self::assertTrue(true);
}
}