diff --git a/src/Phpml/Math/Statistic/Correlation.php b/src/Phpml/Math/Statistic/Correlation.php new file mode 100644 index 0000000..a6047a8 --- /dev/null +++ b/src/Phpml/Math/Statistic/Correlation.php @@ -0,0 +1,45 @@ +assertEquals(-0.641, Correlation::pearson($x, $y), '', $delta); + + //http://www.statisticshowto.com/how-to-compute-pearsons-correlation-coefficients/ + $delta = 0.001; + $x = [43, 21, 25, 42, 57, 59]; + $y = [99, 65, 79, 75, 87, 82]; + $this->assertEquals(0.549, Correlation::pearson($x, $y), '', $delta); + } + + /** + * @expectedException \Phpml\Exception\InvalidArgumentException + */ + public function testThrowExceptionOnInvalidArgumentsForPearsonCorrelation() + { + Correlation::pearson([1, 2, 4], [3, 5]); + } +} diff --git a/tests/Phpml/Math/Statistic/StandardDeviationTest.php b/tests/Phpml/Math/Statistic/StandardDeviationTest.php index ff69f7c..299c979 100644 --- a/tests/Phpml/Math/Statistic/StandardDeviationTest.php +++ b/tests/Phpml/Math/Statistic/StandardDeviationTest.php @@ -39,5 +39,4 @@ class StandardDeviationTest extends \PHPUnit_Framework_TestCase { StandardDeviation::population([1]); } - }