PHP code example of kaydansky / correlation-coefficient

1. Go to this page and download the library: Download kaydansky/correlation-coefficient library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaydansky / correlation-coefficient example snippets




use Correlation\{Correlation, Exception\CorrelationException};

$correlation = new Correlation();

$age = [43, 21, 25, 42, 57, 59];
$glucoseLevel = [99, 65, 79, 75, 87, 81];

try {
    var_dump($correlation->pearson($age, $glucoseLevel));
} catch (CorrelationException $e) {
    echo $e->getMessage();
}

$IQ = [106, 86, 100, 101, 99, 103, 97, 113, 112, 110];
$hoursOfTvPerWeek = [7, 0, 27, 50, 28, 29, 20, 12, 6, 17];

try {
    var_dump($correlation->spearman($IQ, $hoursOfTvPerWeek));
} catch (CorrelationException $e) {
    echo $e->getMessage();
}

$correlation->pearson($arrayX, $arrayY);
$correlation->spearman($arrayX, $arrayY);

float|int $coefficient; // Value from -1 to 1
float|int $percentage; // Same value percentage