In statistics, correlation is a type of statistical relationship between two random variables or bivariate data. It usually refers to the extent to which a pair of quantities are linearly related. More generally, an arbitrary relationship between variables is called an association, meaning the degree to which the variability in one can be accounted for by the other. The presence of a correlation is not sufficient to infer the presence of a causal relationship, and this is often stated as "correlation does not imply causation". Furthermore, the concept of correlation is not the same as dependence: if two variables are independent, then they are uncorrelated, but the opposite is not necessarily true – even if two variables are uncorrelated, they might be dependent on each other. Correlations are useful because they can indicate a predictive relationship that can be exploited in practice. For example, an electrical utility may produce less power on a mild day based on the correlation between electricity demand and weather. In this example, there is a causal relationship, because extreme weather causes people to use more electricity for heating or cooling. There are several correlation coefficients that may be used to measure correlation, often denoted ρ {\displaystyle \rho } or r {\displaystyle r} . The most common of these is the Pearson correlation coefficient, which is sensitive only to a linear relationship between two variables (which in turn may be present even when one variable is a nonlinear function of the other). Other correlation coefficients, such as Spearman's rank correlation coefficient, have been developed to be more robust than Pearson's and to detect less structured relationships between variables. The concept has been generalized to other forms of association between two variables, such as mutual information and distance covariance.
Coefficients
Pearson's product-moment coefficient
The most familiar measure of dependence between two quantities is the Pearson product-moment correlation coefficient, most commonly called 'Pearson's correlation coefficient' or simply 'the correlation coefficient' (as it is the most common variant). It is obtained by taking the ratio of the covariance between two variables of a numerical dataset normalized to the square root of their variances. Equivalently, Pearson's correlation coefficient can be calculated by dividing the covariance of the two variables by the product of their standard deviations. Karl Pearson developed the coefficient from a similar idea by Francis Galton. A Pearson product-moment correlation coefficient attempts to establish a line of best fit through a dataset of two variables by essentially laying out the expected values and the resulting Pearson's correlation coefficient indicates how far away the actual dataset is from the expected values. Depending on the sign of the Pearson's correlation coefficient, the result can be either a negative or positive correlation if there is any sort of relationship between the variables in the data set. The population correlation coefficient ρ X , Y {\displaystyle \rho _{X,Y}} between two random variables X {\displaystyle X} and Y {\displaystyle Y} with expected values μ X {\displaystyle \mu _{X}} and μ Y {\displaystyle \mu _{Y}} and standard deviations σ X {\displaystyle \sigma _{X}} and σ Y {\displaystyle \sigma _{Y}} is defined as:
ρ X , Y = corr ( X , Y ) = cov ( X , Y ) σ X σ Y = E [ ( X − μ X ) ( Y − μ Y ) ] σ X σ Y , if σ X σ Y > 0. {\displaystyle \rho _{X,Y}=\operatorname {corr} (X,Y)={\operatorname {cov} (X,Y) \over \sigma _{X}\sigma _{Y}}={\operatorname {E} [(X-\mu _{X})(Y-\mu _{Y})] \over \sigma _{X}\sigma _{Y}},\quad {\text{if}}\ \sigma _{X}\sigma _{Y}>0.}
where E {\displaystyle \operatorname {E} } is the expected value operator, cov {\displaystyle \operatorname {cov} } means covariance, and corr {\displaystyle \operatorname {corr} } is a widely used alternative notation for the correlation coefficient. The Pearson correlation is defined only if both standard deviations are finite and positive. An alternative formula purely in terms of moments is:
ρ X , Y = E ( X Y ) − E ( X ) E ( Y ) E ( X 2 ) − E ( X ) 2 ⋅ E ( Y 2 ) − E ( Y ) 2 {\displaystyle \rho _{X,Y}={\operatorname {E} (XY)-\operatorname {E} (X)\operatorname {E} (Y) \over {\sqrt {\operatorname {E} (X^{2})-\operatorname {E} (X)^{2}}}\cdot {\sqrt {\operatorname {E} (Y^{2})-\operatorname {E} (Y)^{2}}}}}
Correlation and independence It is a corollary of the Cauchy–Schwarz inequality that the absolute value of the Pearson correlation coefficient is not bigger than 1. Therefore, the value of a correlation coefficient ranges between −1 and +1. The correlation coefficient is +1 in the case of a perfect direct (increasing) linear relationship (correlation), −1 in the case of a perfect inverse (decreasing) linear relationship (anti-correlation), and some value in the open interval ( − 1 , 1 ) {\displaystyle (-1,1)} in all other cases, indicating the degree of linear dependence between the variables. As it approaches zero there is less of a relationship (closer to uncorrelated). The closer the coefficient is to either −1 or 1, the stronger the correlation between the variables. If the variables are independent, Pearson's correlation coefficient is 0. However, because the correlation coefficient detects only linear dependencies between two variables, the converse is not necessarily true. A correlation coefficient of 0 does not imply that the variables are independent.
X , Y independent ⇒ ρ X , Y = 0 ( X , Y uncorrelated ) ρ X , Y = 0 ( X , Y uncorrelated ) ⇏ X , Y independent {\displaystyle {\begin{aligned}X,Y{\text{ independent}}\quad &\Rightarrow \quad \rho _{X,Y}=0\quad (X,Y{\text{ uncorrelated}})\\\rho _{X,Y}=0\quad (X,Y{\text{ uncorrelated}})\quad &\nRightarrow \quad X,Y{\text{ independent}}\end{aligned}}}
For example, suppose the random variable X {\displaystyle X} is symmetrically distributed about zero, and Y = X 2 {\displaystyle Y=X^{2}} . Then Y {\displaystyle Y} is completely determined by X {\displaystyle X} , so that X {\displaystyle X} and Y {\displaystyle Y} are perfectly dependent, but their correlation is zero; they are uncorrelated. However, in the special case when X {\displaystyle X} and Y {\displaystyle Y} are jointly normal, uncorrelatedness is equivalent to independence. Even though uncorrelated data does not necessarily imply independence, one can check if random variables are independent if their mutual information is 0.
Sample correlation coefficient Given a series of n {\displaystyle n} measurements of the pair ( X i , Y i ) {\displaystyle (X_{i},Y_{i})} indexed by i = 1 , … , n {\displaystyle i=1,\ldots ,n} , the sample correlation coefficient can be used to estimate the population Pearson correlation ρ X , Y {\displaystyle \rho _{X,Y}} between X {\displaystyle X} and Y {\displaystyle Y} . The sample correlation coefficient is defined as
r x y = d e f ∑ i = 1 n ( x i − x ¯ ) ( y i − y ¯ ) ( n − 1 ) s x s y = ∑ i = 1 n ( x i − x ¯ ) ( y i − y ¯ ) ∑ i = 1 n ( x i − x ¯ ) 2 ∑ i = 1 n ( y i − y ¯ ) 2 , {\displaystyle r_{xy}\quad {\overset {\underset {\mathrm {def} }{}}{=}}\quad {\frac {\sum \limits _{i=1}^{n}(x_{i}-{\bar {x}})(y_{i}-{\bar {y}})}{(n-1)s_{x}s_{y}}}={\frac {\sum \limits _{i=1}^{n}(x_{i}-{\bar {x}})(y_{i}-{\bar {y}})}{\sqrt {\sum \limits _{i=1}^{n}(x_{i}-{\bar {x}})^{2}\sum \limits _{i=1}^{n}(y_{i}-{\bar {y}})^{2}}}},}
where x ¯ {\displaystyle {\overline {x}}} and y ¯ {\displaystyle {\overline {y}}} are the sample means of X {\displaystyle X} and Y {\displaystyle Y} , and s x {\displaystyle s_{x}} and s y {\displaystyle s_{y}} are the corrected sample standard deviations of X {\displaystyle X} and Y {\displaystyle Y} . Equivalent expressions for r x y {\displaystyle r_{xy}} are
r x y = ∑ x i y i − n x ¯ y ¯ n s x ′ s y ′ = n ∑ x i y i − ∑ x i ∑ y i n ∑ x i 2 − ( ∑ x i ) 2 n ∑ y i 2 − ( ∑ y i ) 2 . {\displaystyle {\begin{aligned}r_{xy}&={\frac {\sum x_{i}y_{i}-n{\bar {x}}{\bar {y}}}{ns'_{x}s'_{y}}}\\[5pt]&={\frac {n\sum x_{i}y_{i}-\sum x_{i}\sum y_{i}}{{\sqrt {n\sum x_{i}^{2}-(\sum x_{i})^{2}}}~{\sqrt {n\sum y_{i}^{2}-(\sum y_{i})^{2}}}}}.\end{aligned}}}
where s x ′ {\displaystyle s'_{x}} and s y ′ {\displaystyle s'_{y}} are the uncorrected sample standard deviations of X {\displaystyle X} and Y {\displaystyle Y} . If x {\displaystyle x} and y {\displaystyle y} are results of measurements that contain measurement error, the realistic limits on the correlation coefficient are not −1 to +1 but a smaller range. For the case of a linear model with a single independent variable, the coefficient of determination (R squared) is the square of r x y {\displaystyle r_{xy}} , Pearson's product-moment coefficient.
Example Consider the joint probability distribution of X and Y given in the table below.
For this joint distribution, the marginal distributions are:
P ( X = x ) = { 1 3 for x = 0 2 3 for x = 1 {\displaystyle \mathrm {P} (X=x)={\begin{cases}{\frac {1}{3}}&\quad {\text{for }}x=0\\{\frac {2}{3}}&\quad {\text{for }}x=1\end{cases}}}
P ( Y = y ) = { 1 3 for y = − 1 1 3 for y = 0 1 3 for y = 1 {\displaystyle \mathrm {P} (Y=y)={\begin{cases}{\frac {1}{3}}&\quad {\text{for }}y=-1\\{\frac {1}{3}}&\quad {\text{for }}y=0\\{\frac {1}{3}}&\quad {\text{for }}y=1\end{cases}}}
This yields the following expectations and variances:
μ X = 2 3 {\displaystyle \mu _{X}={\frac {2}{3}}}
μ Y = 0 {\displaystyle \mu _{Y}=0}
σ X 2 = 2 9 {\displaystyle \sigma _{X}^{2}={\frac {2}{9}}}
σ Y 2 = 2 3 {\displaystyle \sigma _{Y}^{2}={\frac {2}{3}}}
Therefore:
ρ X , Y = 1 σ X σ Y E [ ( X − μ X ) ( Y − μ Y ) ] = 1 σ X σ Y ∑ x , y ( x − μ X ) ( y − μ Y ) P ( X = x , Y = y ) = 3 3 2 ( ( 1 − 2 3 ) ( − 1 − 0 ) 1 3 + ( 0 − 2 3 ) ( 0 − 0 ) 1 3 + ( 1 − 2 3 ) ( 1 − 0 ) 1 3 ) = 0. {\displaystyle {\begin{aligned}\rho _{X,Y}&={\frac {1}{\sigma _{X}\sigma _{Y}}}\mathrm {E} [(X-\mu _{X})(Y-\mu _{Y})]\\[5pt]&={\frac {1}{\sigma _{X}\sigma _{Y}}}\sum _{x,y}{(x-\mu _{X})(y-\mu _{Y})\mathrm {P} (X=x,Y=y)}\\[5pt]&={\frac {3{\sqrt {3}}}{2}}\left(\left(1-{\frac {2}{3}}\right)(-1-0){\frac {1}{3}}+\left(0-{\frac {2}{3}}\right)(0-0){\frac {1}{3}}+\left(1-{\frac {2}{3}}\right)(1-0){\frac {1}{3}}\right)=0.\end{aligned}}}
Rank correlation coefficients
Rank correlation coefficients, such as Spearman's rank correlation coefficient and Kendall's rank correlation coefficient (τ) measure the extent to which, as one variable increases, the other variable tends to increase, without requiring that increase to be represented by a linear relationship. If, as the one variable increases, the other decreases, the rank correlation coefficients will be negative. It is common to regard these rank correlation coefficients as alternatives to Pearson's coefficient, used either to reduce the amount of calculation or to make the coefficient less sensitive to non-normality in distributions. However, this view has little mathematical basis, as rank correlation coefficients measure a different type of relationship than the Pearson product-moment correlation coefficient, and are best seen as measures of a different type of association, rather than as an alternative measure of the population correlation coefficient. To illustrate the nature of rank correlation, and its difference from linear correlation, consider the following four pairs of numbers ( x , y ) {\displaystyle (x,y)} :
(0, 1), (10, 100), (101, 500), (102, 2000). As we go from each pair to the next pair, x {\displaystyle x} increases, and so does y {\displaystyle y} . This relationship is perfect, in the sense that an increase in x {\displaystyle x} is always accompanied by an increase in y {\displaystyle y} . This means that we have a perfect rank correlation, and both Spearman's and Kendall's correlation coefficients are 1, whereas in this example Pearson product-moment correlation coefficient is 0.7544, indicating that the points are far from lying on a straight line. In the same way if y {\displaystyle y} always decreases when x {\displaystyle x} increases, the rank correlation coefficients will be −1, while the Pearson product-moment correlation coefficient may or may not be close to −1, depending on how close the points are to a straight line. Although in the extreme cases of perfect rank correlation the two coefficients are both equal (being both +1 or both −1), this is not generally the case, and so values of the two coefficients cannot meaningfully be compared. For example, for the three pairs (1, 1) (2, 3) (3, 2) Spearman's coefficient is 1/2, while Kendall's coefficient is 1/3.
Common misconceptions
Correlation and causality The conventional dictum that "correlation does not imply causation" means that correlation cannot be used by itself to infer a causal relationship between the variables. This dictum should not be taken to mean that correlations cannot indicate the potential existence of causal relations. However, the causes underlying the correlation, if any, may be indirect and unknown, and high correlations also overlap with identity relations (tautologies), where no causal process exists (e.g., between two variables measuring the same construct). Consequently, a correlation between two variables is not a sufficient condition to establish a causal relationship (in either direction). A correlation between age and height in children is fairly causally transparent, but a correlation between mood and health in people is less so. Does improved mood lead to improved health, or does good health lead to good mood, or both? Or does some other factor underlie both? In other words, a correlation can be taken as evidence for a possible causal relationship, but cannot indicate what the causal relationship, if any, might be.
Simple linear correlations
The Pearson correlation coefficient indicates the strength of a linear relationship between two variables, but its value generally does not completely characterize their relationship. In particular, if the conditional mean of Y {\displaystyle Y} given X {\displaystyle X} , denoted E ( Y ∣ X ) {\displaystyle \operatorname {E} (Y\mid X)} , is not linear in X {\displaystyle X} , the correlation coefficient will not fully determine the form of E ( Y ∣ X ) {\displaystyle \operatorname {E} (Y\mid X)} . The adjacent image shows scatter plots of Anscombe's quartet, a set of four different pairs of variables created by Francis Anscombe. The four y {\displaystyle y} variables have the same mean (7.5), variance (4.12), correlation (0.816) and regression line ( y = 3 + 0.5 x {\textstyle y=3+0.5x} ). However, as can be seen on the plots, the distribution of the variables is very different. The first one (top left) seems to be distributed normally, and corresponds to what one would expect when considering two variables correlated and following the assumption of normality. The second one (top right) is not distributed normally; while an obvious relationship between the two variables can be observed, it is not linear. In this case the Pearson correlation coefficient does not indicate that there is an exact functional relationship: only the extent to which that relationship can be approximated by a linear relationship. In the third case (bottom left), the linear relationship is perfect, except for one outlier which exerts enough influence to lower the correlation coefficient from 1 to 0.816. Finally, the fourth example (bottom right) shows another example when one outlier is enough to produce a high correlation coefficient, even though the relationship between the two variables is not linear. These examples indicate that the correlation coefficient, as a summary statistic, cannot replace visual examination of the data. The examples are sometimes said to demonstrate that the Pearson correlation assumes that the data follow a normal distribution, but this is only partially correct. The Pearson correlation can be accurately calculated for any distribution that has a finite covariance matrix, which includes most distributions encountered in practice. However, the Pearson correlation coefficient (taken together with the sample mean and variance) is only a sufficient statistic if the data is drawn from a multivariate normal distribution. As a result, the Pearson correlation coefficient fully characterizes the relationship between variables if and only if the data are drawn from a multivariate normal distribution.
Properties
Uncorrelatedness and independence of stochastic processes Similarly for two stochastic processes { X t }
