math-php
Static Public Member Functions | Public Attributes | List of all members
MathPHP\Statistics\Correlation Class Reference

Statistical correlation. More...

Static Public Member Functions

static covariance (array $X, array $Y, bool $population=false)
 Covariance Convenience method to access population and sample covariance. More...
 
static populationCovariance (array $X, array $Y)
 Population Covariance A measure of how much two random variables change together. More...
 
static sampleCovariance (array $X, array $Y)
 Sample covariance A measure of how much two random variables change together. More...
 
static weightedCovariance (array $X, array $Y, array $w)
 Weighted covariance A measure of how much two random variables change together with weights. More...
 
static r (array $X, array $Y, bool $population=false)
 r - correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r) More...
 
static populationCorrelationCoefficient (array $X, array $Y)
 Population correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r) More...
 
static sampleCorrelationCoefficient (array $X, array $Y)
 Sample correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r) More...
 
static r2 (array $X, array $Y, bool $popluation=false)
 R² - coefficient of determination Convenience wrapper for coefficientOfDetermination. More...
 
static coefficientOfDetermination (array $X, array $Y, bool $popluation=false)
 R² - coefficient of determination. More...
 
static weightedCorrelationCoefficient (array $X, array $Y, array $w)
 Weighted correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r) width weighted values. More...
 
static kendallsTau (array $X, array $Y)
 τ - Kendall rank correlation coefficient (Kendall's tau) More...
 
static spearmansRho (array $X, array $Y)
 ρ - Spearman's rank correlation coefficient (Spearman's rho) More...
 
static describe (array $X, array $Y, bool $population=false)
 Descriptive correlation report about two random variables. More...
 
static confidenceEllipse (array $X, array $Y, float $z, int $num_points=11)
 Confidence ellipse (error ellipse) Given the data in $X and $Y, create an ellipse surrounding the data at $z standard deviations. More...
 

Public Attributes

const X = 0
 
const Y = 1
 

Detailed Description

Statistical correlation.

Member Function Documentation

◆ coefficientOfDetermination()

static MathPHP\Statistics\Correlation::coefficientOfDetermination ( array  $X,
array  $Y,
bool  $popluation = false 
)
static

R² - coefficient of determination.

Indicates the proportion of the variance in the dependent variable that is predictable from the independent variable. Range of 0 - 1. Close to 1 means the regression line is a good fit https://en.wikipedia.org/wiki/Coefficient_of_determination

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
bool$popluation
Returns
float
Exceptions
Exception

◆ confidenceEllipse()

static MathPHP\Statistics\Correlation::confidenceEllipse ( array  $X,
array  $Y,
float  $z,
int  $num_points = 11 
)
static

Confidence ellipse (error ellipse) Given the data in $X and $Y, create an ellipse surrounding the data at $z standard deviations.

The function will return $num_points pairs of X,Y data http://stackoverflow.com/questions/3417028/ellipse-around-the-data-in-matlab

Parameters
array$Xan array of independent data
array$Yan array of dependent data
float$zthe number of standard deviations to encompass
int$num_pointsthe number of points to include around the ellipse. The actual array will be one larger because the first point and last will be repeated to ease display.
Returns
array paired x and y points on an ellipse aligned with the data provided
Exceptions
Exception

◆ covariance()

static MathPHP\Statistics\Correlation::covariance ( array  $X,
array  $Y,
bool  $population = false 
)
static

Covariance Convenience method to access population and sample covariance.

A measure of how much two random variables change together. Average product of their deviations from their respective means. The population covariance is defined in terms of the sample means x, y https://en.wikipedia.org/wiki/Covariance

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
bool$populationOptional flag for population or sample covariance
Returns
float
Exceptions
Exception

◆ describe()

static MathPHP\Statistics\Correlation::describe ( array  $X,
array  $Y,
bool  $population = false 
)
static

Descriptive correlation report about two random variables.

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
bool$populationOptional flag if all samples of a population are present
Returns
array [cov, r, R2, tau, rho]
Exceptions
Exception

◆ kendallsTau()

static MathPHP\Statistics\Correlation::kendallsTau ( array  $X,
array  $Y 
)
static

τ - Kendall rank correlation coefficient (Kendall's tau)

A statistic used to measure the ordinal association between two measured quantities. It is a measure of rank correlation: the similarity of the orderings of the data when ranked by each of the quantities. https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient https://onlinecourses.science.psu.edu/stat509/node/158

tau-a (no rank ties):

   nc - nd

τ = -------— n(n - 1)/2

Where nc: number of concordant pairs nd: number of discordant pairs

tau-b (rank ties exist):

            nc - nd

τ = --------------------------— √(nc + nd + X₀)(nc + nd + Y₀)

Where X₀: number of pairs tied only on the X variable Y₀: number of pairs tied only on the Y variable

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Todo:
Implement with algorithm faster than O(n²)
Returns
float
Exceptions
Exception

◆ populationCorrelationCoefficient()

static MathPHP\Statistics\Correlation::populationCorrelationCoefficient ( array  $X,
array  $Y 
)
static

Population correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r)

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.

   cov(X,Y)

ρxy = -------— σx σy

conv(X,Y) is the population covariance σx is the population standard deviation of X σy is the population standard deviation of Y

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Returns
float
Exceptions
Exception

◆ populationCovariance()

static MathPHP\Statistics\Correlation::populationCovariance ( array  $X,
array  $Y 
)
static

Population Covariance A measure of how much two random variables change together.

Average product of their deviations from their respective means. The population covariance is defined in terms of the population means μx, μy https://en.wikipedia.org/wiki/Covariance

cov(X, Y) = σxy = E[⟮X - μx⟯⟮Y - μy⟯]

              ∑⟮xᵢ - μₓ⟯⟮yᵢ - μy⟯

cov(X, Y) = σxy = --------------— N

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Returns
float
Exceptions
Exception

◆ r()

static MathPHP\Statistics\Correlation::r ( array  $X,
array  $Y,
bool  $population = false 
)
static

r - correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r)

Convenience method for population and sample correlationCoefficient

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
bool$populationOptional flag for population or sample covariance
Returns
float
Exceptions
Exception

◆ r2()

static MathPHP\Statistics\Correlation::r2 ( array  $X,
array  $Y,
bool  $popluation = false 
)
static

R² - coefficient of determination Convenience wrapper for coefficientOfDetermination.

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
bool$popluation
Returns
float
Exceptions
Exception

◆ sampleCorrelationCoefficient()

static MathPHP\Statistics\Correlation::sampleCorrelationCoefficient ( array  $X,
array  $Y 
)
static

Sample correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r)

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

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Returns
float
Exceptions
Exception

◆ sampleCovariance()

static MathPHP\Statistics\Correlation::sampleCovariance ( array  $X,
array  $Y 
)
static

Sample covariance A measure of how much two random variables change together.

Average product of their deviations from their respective means. The population covariance is defined in terms of the sample means x, y https://en.wikipedia.org/wiki/Covariance

cov(X, Y) = Sxy = E[⟮X - x⟯⟮Y - y⟯]

              ∑⟮xᵢ - x⟯⟮yᵢ - y⟯

cov(X, Y) = Sxy = ------------— n - 1

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Returns
float
Exceptions
Exception

◆ spearmansRho()

static MathPHP\Statistics\Correlation::spearmansRho ( array  $X,
array  $Y 
)
static

ρ - Spearman's rank correlation coefficient (Spearman's rho)

https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient

     6 ∑ dᵢ²

ρ = 1 - ------— n(n² − 1)

Where dᵢ: the difference between the two ranks of each observation

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
Returns
float
Exceptions
Exception

◆ weightedCorrelationCoefficient()

static MathPHP\Statistics\Correlation::weightedCorrelationCoefficient ( array  $X,
array  $Y,
array  $w 
)
static

Weighted correlation coefficient Pearson product-moment correlation coefficient (PPMCC or PCC or Pearson's r) width weighted values.

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_correlation_coefficient#Weighted_correlation_coefficient

The weighted correlation coefficient of two variables in a data sample is their covariance divided by the product of their individual standard deviations.

     cov(X,Y,w)

ρxyw = ----------— √(sxw syw)

conv(X,Y, w) is the weighted covariance sxw is the weighted variance of X syw is the weighted variance of Y

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
array$wvalues for weights
Returns
float
Exceptions
Exception

◆ weightedCovariance()

static MathPHP\Statistics\Correlation::weightedCovariance ( array  $X,
array  $Y,
array  $w 
)
static

Weighted covariance A measure of how much two random variables change together with weights.

https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Weighted_correlation_coefficient

                  ∑wᵢ⟮xᵢ - μₓ⟯⟮yᵢ - μy⟯

cov(X, Y, w) = sxyw = -----------------— ∑wᵢ

Parameters
array$Xvalues for random variable X
array$Yvalues for random variable Y
array$wvalues for weights
Returns
float
Exceptions
Exception

The documentation for this class was generated from the following file: