MathPHP\Statistics\Correlation::sampleCorrelationCoefficient PHP Метод

sampleCorrelationCoefficient() публичный статический Метод

A normalized measure of the linear correlation between two variables X and Y, giving a value between +1 and −1 inclusive, where 1 is total positive correlation, 0 is no correlation, and −1 is total negative correlation. It is widely used in the sciences as a measure of the degree of linear dependence between two variables. https://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient The correlation coefficient of two variables in a data sample is their covariance divided by the product of their individual standard deviations. Sxy rxy = ---------- sx sy Sxy is the sample covariance σx is the sample standard deviation of X σy is the sample standard deviation of Y
public static sampleCorrelationCoefficient ( array $X, array $Y ) : number
$X array values for random variable X
$Y array values for random variable Y
Результат number
    public static function sampleCorrelationCoefficient(array $X, array $Y)
    {
        $Sxy = self::sampleCovariance($X, $Y);
        $sx = Descriptive::standardDeviation($X, Descriptive::SAMPLE);
        $sy = Descriptive::standardDeviation($Y, Descriptive::SAMPLE);
        return $Sxy / ($sx * $sy);
    }