Skip to content

kaydansky/correlation-coefficient

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

Correlation Coefficient Calculation

A correlation coefficient is a numerical measure of some type of correlation, meaning a statistical relationship between two variables.

A statistic used to show how the scores from one measure relate to scores on a second measure for the same group of individuals. A high value (approaching +1.00) is a strong direct relationship, a low negative value (approaching -1.00) is a strong inverse relationship, and values near 0.00 indicate little, if any, relationship.

Learn more

Features

Two types of correlation coefficient are implemented currently:

Unlimited instance number of every type's object.

Example of usage:

Correlation Coefficient Calculator

Requirements

  • PHP >= 7.4.0

Installation

$ composer require kaydansky/correlation-coefficient

Basic Usage

<?php

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();
}
  • The library provides 2 methods according to coefficient type:
$correlation->pearson($arrayX, $arrayY);
$correlation->spearman($arrayX, $arrayY);
  • Each method returns an object with 2 elements:
float|int $coefficient; // Value from -1 to 1
float|int $percentage; // Same value percentage
  • Every array must contain numeric values only: integer, float, numeric string.
  • Arrays pair must have equal number of elements.

License

This software is licensed under the MIT License. See the LICENSE file for details.

About

The correlation coefficient is a statistical measure that calculates the strength of the relationship between the relative movements of two variables.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages