2018-02-11 21:10:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Phpml\Tests\Math\Statistic;
|
|
|
|
|
|
|
|
use Phpml\Exception\InvalidArgumentException;
|
|
|
|
use Phpml\Math\Statistic\ANOVA;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
final class ANOVATest extends TestCase
|
|
|
|
{
|
|
|
|
public function testOneWayF(): void
|
|
|
|
{
|
|
|
|
$samples = [
|
|
|
|
[[1, 2, 1], [1, 3, 4], [5, 2, 1]],
|
|
|
|
[[1, 3, 3], [1, 3, 4], [0, 3, 5]],
|
|
|
|
];
|
|
|
|
|
|
|
|
$f = [1.47058824, 4.0, 3.0];
|
|
|
|
|
2019-04-10 18:42:59 +00:00
|
|
|
self::assertEqualsWithDelta($f, ANOVA::oneWayF($samples), 0.00000001);
|
2018-02-11 21:10:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneWayFWithDifferingSizes(): void
|
|
|
|
{
|
|
|
|
$samples = [
|
|
|
|
[[1, 2, 1], [1, 3, 4], [5, 2, 1]],
|
|
|
|
[[1, 3, 3], [1, 3, 4]],
|
|
|
|
];
|
|
|
|
|
2019-04-10 18:42:59 +00:00
|
|
|
self::assertEqualsWithDelta([0.6, 2.4, 1.24615385], ANOVA::oneWayF($samples), 0.00000001);
|
2018-02-11 21:10:12 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 17:14:06 +00:00
|
|
|
public function testThrowExceptionOnTooSmallSamples(): void
|
2018-02-11 21:10:12 +00:00
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$samples = [
|
|
|
|
[[1, 2, 1], [1, 3, 4], [5, 2, 1]],
|
|
|
|
];
|
|
|
|
|
|
|
|
ANOVA::oneWayF($samples);
|
|
|
|
}
|
|
|
|
}
|