Korélasi

::*Artikel ieu ngeunaan koefisien korelasi antara dua variable acak. Watesan *korelasi* bisa ogé hartina korelasi silang dua fungsi.*

Dina tiori probabiliti jeung statistik, **korelasi**, disebut ogé **koefisien korelasi**, nyaéta ukuran numerik ngeunaan kuatna hubungan linier antara dua variabel acak. Dina pamakéan statistik nu ilahar, *korelas* atawa ko-relasi nujul kana pakaitna dua variabel bebéas. Dina hal nu leuwih lega, aya sababaraha koefisien, ukuran tingkat pakait nu dicokot tina data alam atawa data asli.

gedéna béda korelasi dipaké keur kaayaan nu béda. Nu panghadéna nyaéta korefisien korelasi produk-momen Pearson, nu ditangtukeun ku cara ngabagi kovarian dua variabel ku hasil kali simpangan bakuna. Korelasi mimiti diwanohkeun ku Francis Galton.

## Koefisien produk-momen Pearson 
### Pasipatan Matematika 
Korelasi &rho;xy antara dua variabel acak *X* and *Y* jeung nilai ekspektasi &mu;X jeung &mu;Y sarta simpangan baku &sigma;X jeung &sigma;Y dihartikeun:
:
\rho_{xy}={\mathrm{cov}(X,Y) \over \sigma_X \sigma_Y} ={E((X-\mu_X)(Y-\mu_Y)) \over \sigma_X\sigma_Y}.

Anggap &mu;X=E(X), 
&sigma;X2=E(X2)-E2(X) tur saperti keur Y, bisa ogé dituliskeun jadi:

:\rho_{xy}=\frac{E(XY)-E(X)E(Y)}{\sqrt{E(X^2)-E^2(X)}~\sqrt{E(Y^2)-E^2(Y)}}

Korélasi bisa dihartikeun lamun simpangan baku kawengku tur salah sahijina lain enol.  Rumusan itu dina kateusaruaan Cauchy-Schwarz yén korelasi teu bisa leuwih ti 1 dina nilai mutlakna.

Korelasi sarua jeung 1 lamun mibanda hubungan naek sacara liner, &minus;1 lamun mibanda hubungan turun linier, tur sababaraha nilai di antarana keur sakabéh pasualan, nunjukkeun tingkat sakumaha gumantungna variabel sacara linier. Koefisien nu pangdeukeutna boh kana  &minus;1 atawa 1, mibanda  harti beuki kuat korelasi antara dua variabel eta.

Lamun variabel mandiri mangka korelasina bakal 0, tapi teu salawasna bener sabab koefisien korelasi ngan keur néangan kabébasan linier antara dua variabel. Contona: Anggap variabel acak *X* mangrupa sebaran seragam dina interval ti &minus;1 ka 1, sarta *Y* = *X*2.  Mangka *Y* satemenna ditangtukeun ku *X*, sabab kitu *X* tur *Y* bisa waé asalna tina dua variabel acak mandiri, tapi korelasi nol; maranéhna taya korelasi. Sanajan kitu, dina kasus basa *X* tur *Y* ngahiji normal, mandiri sarua jeung taya korelasi.

### Korelasi sampel 
Lamun hiji runtuyan *n*&nbsp; tina hasil ngukur *X*&nbsp; tur *Y*&nbsp; dituliskeun salaku *xi*&nbsp; tur *yi*&nbsp; nu mana *i* = 1, 2, ..., *n*, mangka koefisien korelasi produk-momen Pearson bisa dipaké keur ngiker korelasi *X*&nbsp; jeung *Y*&nbsp;. Koefisien Péarson disebut ogé "koefisien korelasi sampel". Hal ieu husus lamun *X*&nbsp; tur *Y*&nbsp; duanana kasebar normal. Koefisien korelasi  Péarson jadi estimasi nu hadé keur korelasi *X*&nbsp; jeung *Y*&nbsp;. Koefisien korelasi Péarson ditulis:

:
r_{xy}=\frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{(n-1) s_x s_y}

nu mana \bar{x} jeung \bar{y} nyaéta rata-rata tina *xi*&nbsp; jeung *yi*&nbsp;, *s**x*&nbsp; jeung *s**y*&nbsp; nyaéta simpangan baku tina  *xi*&nbsp; jeung *yi*&nbsp; sarta jumlahna ti *i* = 1 nepi ka *n*. Saperti dina korelasi populasi, bisa ditulis salaku

:
r_{xy}=\frac{n\sum x_iy_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}}.

Sakali deui, ieu bener dina korelasi populasi, gedéna nilai mutlak sampel korelasi kudu kurang atawa sarua jeung 1. ngagunakeun rumus di luhur mangrupa hal nu ilahar dipaké dina algoritma tunggal keur ngitung korelasi sampel, hal ieu teu stabil dina itungan sacara numerik (tempo di handap keur nu leuwih jéntré).

Kuadrat koefisien korelasi sampel, disebut ogé koefisien determinasi, nyaéta bagéan tina varian dina *yi*&nbsp; nu diitung ku cara fit linier *xi*&nbsp; ka *yi*&nbsp;. Ditulis

:r_{xy}^2=1-\frac{s_{y|x}^2}{s_y^2},

nu mana *s**y*|*x*2&nbsp; nyaéta kuadrat kasalahan régrési liniér  *xi*&nbsp; dina *yi*&nbsp; ku sasaruan *y = a + bx*:

:s_{y|x}^2=\frac{1}{n-1}\sum_{i=1}^n (y_i-a-bx_i)^2,

jeung *s**y*2&nbsp; nyaéta ngan varian *y*:

:s_y^2=\frac{1}{n-1}\sum_{i=1}^n (y_i-\bar{y})^2.

Catetan, lamun koéfisien sampel korélasi simetri dina *xi*&nbsp; jeung *yi*&nbsp;, bakal meunang niley nu sarua keur fit *yi*&nbsp; ka *xi*&nbsp;:

:r_{xy}^2=1-\frac{s_{x|y}^2}{s_x^2}.

Ieu sasaruan méré ide keur dimensi nu leuwih luhur. Saperti nu dijelaskeun di luhur korélasi koéfsien sampel nyaéta bagéan tian itungan varian ku cara nga-fit-keun linear submanifold 1-dimensi kana runtuyan vektor (*xi*&nbsp;, *yi*&nbsp;) 2 dimensi, mangka bisa dihartikeun koefisien korelasi keur fit dina *m*-dimensi linéar submanifold kana runtuyan vektor *n*-dimensi. Contona, lamun nga-fit-keun widang *z = a + bx + cy*&nbsp; kana runtuyan data (*xi*&nbsp;, *yi*&nbsp;, *zi*&nbsp;) mangka koefisien korelasi  *z*&nbsp; ka *x*&nbsp; jeung *y*&nbsp; nyaéta

:r^2=1-\frac{s_{z|xy}^2}{s_z^2}.

Sebaran koefisien korelasi geus diterangkeun ku R. A. Fisher
jeung A. K. Gayen.

### Interpretasi korélasi sacara geometri
Koéfisién korélasi bisa ogé ditempo salaku kosinus sudut antara dua vektor sampel nu dicokot tina dua variabel acak.

Caution: This method only works  with centered data, i.e., data which have been shifted by the sample méan so as to have an average of zero. Some practitioners prefer an uncentered (non-Péarson-compliant) correlation coefficient. See the example below for a comparison.

As an example, suppose five countries are found to have gross national products of 1, 2, 3, 5, and 8 billion dollars, respectively. Suppose these same five countries (in the same order) are found to have 11%, 12%, 13%, 15%, and 18% poverty. Then let **x** and **y** be ordered 5-element vectors containing the above data: **x** = (1, 2, 3, 5, 8) and **y** = (0.11, 0.12, 0.13, 0.15, 0.18).

By the usual procedure for finding the angle  between two vectors (see dot product), the *uncentered* correlation coefficient is:

 
: \cos \theta = \frac { \mathbf{x} \cdot \mathbf{y} } { \left\| \mathbf{x} \right\| \left\| \mathbf{y} \right\| } = \frac { 2.93 } { \sqrt { 103 } \sqrt { 0.0983 } } = 0.920814711. 

Note that the above data were deliberately chosen to be perfectly correlated: *y* = 0.10 + 0.01 *x*. The Péarson correlation coefficient must therefore be exactly one. Centering the data (shifting **x** by E(**x**) = 3.8 and **y** by E(**y**) = 0.138) yields **x** = (-2.8, -1.8, -0.8, 1.2, 4.2) and **y** = (-0.028, -0.018, -0.008, 0.012, 0.042), from which

 
: \cos \theta = \frac { \mathbf{x} \cdot \mathbf{y} } { \left\| \mathbf{x} \right\| \left\| \mathbf{y} \right\| } = \frac { 0.308 } { \sqrt { 30.8 } \sqrt { 0.00308 } } = 1, 

as expected.

### Interpretation of the size of a correlation
Several authors have offered guidelines for the interpretation of a correlation coefficient.  Cohen (1988), for example, has suggested the following interpretations for correlations in psychological reséarch, in the table on the right.

As Cohen himself has observed, however, all such criteria are in some ways arbitrary and should not be observed too strictly.  This is because the interpretation of a correlation coefficient depends on the context and purposes.  A correlation of 0.9 may be very low if one is verifying a physical law using high-quality instruments, but may be regarded as very high in the social sciences where there may be a gréater contribution from complicating factors.

## Non-parametric correlation coefficients
Péarson's correlation coefficient is a parametric statistic and when distributions are not normal it may be less useful than non-parametric correlation methods, such as Chi-square, Point biserial correlation, Spearman's &rho; and Kendall's &tau;.  They are a little less powerful than parametric methods if the assumptions underlying the latter are met, but are less likely to give distorted results when the assumptions fail.

## Other measures of dependence among random variables
To get a méasure for more general dependencies in the data (also nonlinéar) it is better to use the correlation ratio which is able to detect almost any functional dependency, or mutual information/total correlation which is capable of detecting even more general dependencies.

The polychoric correlation is another correlation applied to ordinal data that aims to estimate the correlation between théorised latent variables.

## Copulas and correlation
The information given by a correlation coefficient is not enough to define the dependence structure between random variables;  to fully capture it we must consider a copula between them. The correlation coefficient completely defines the dependence structure only in very particular cases, for example when the cumulative distribution functions are the multivariate normal distributions. In the case of elliptic distributions it characterizes the (hyper-)ellipses of equal density, however, it does not completely characterize the dependence structure (for example, the a multivariate t-distribution's degrees of freedom determine the level of tail dependence).

## Correlation matrices
The correlation matrix of *n* random variables *X*1, ..., *X**n* is the *n*&nbsp; &times; &nbsp;*n* matrix whose *i*,*j* entry is corr(*X**i*,&nbsp;*X**j*).  If the méasures of correlation used are product-moment coefficients, the correlation matrix is the same as the covariance matrix of the standardized random variables *X**i* /SD(*X**i*) for *i* = 1,&nbsp;...,&nbsp;*n*.  Consequently it is necessarily a positive-semidefinite matrix.

The correlation matrix is symmetric because the correlation between X_i and X_j is the same as the correlation between X_j and X_i.

## Removing correlation
It is always possible to remove the correlation between zero-méan random variables with a linéar transform, even if the relationship between the variables is nonlinéar.  Suppose a vector of *n* random variables is sampled *m* times.  Let *X* be a matrix where X_{i,j} is the *j*th variable of sample *i*.  Let Z_{r,c} be an *r* by *c* matrix with every element 1.  Then *D* is the data transformed so every random variable has zero méan, and *T* is the data transformed so all variables have zero méan, unit variance, and zero correlation with all other variables.

:D = X -\frac{1}{m} Z_{m,m} X
:T = D (D^T D)^{-\frac{1}{2}}

where an exponent of -1/2 represents the matrix square root of the inverse of a matrix.  The covariance matrix of *T* will be the identity matrix.  If a new data sample *x* is a row vector of *n* elements, then the same transform can be applied to *x* to get the transformed vectors *d* and *t*:

:d = x - \frac{1}{m} Z_{1,m} X
:t = d (D^T D)^{-\frac{1}{2}}.

## Common misconceptions about correlation
### Correlation and causality
The conventional dictum that "correlation does not imply causation" méans that correlation cannot be validly used to infer a causal relationship between the variables. This dictum should not be taken to méan that correlations cannot indicate causal relations. However, the causes underlying the correlation, if any, may be indirect and unknown. Consequently, establishing a correlation between two variables is not a sufficient condition to establish a causal relationship (in either direction).

Here is a simple example: hot wéather may cause both crime and ice-créam purchases.  Therefore crime is correlated with ice-créam purchases.  But crime does not cause ice-créam purchases and ice-créam purchases do not cause crime.

A correlation between age and height in children is fairly causally transparent, but a correlation between mood and héalth in péople is less so. Does improved mood léad to improved héalth? Or does good héalth léad to good mood? Or does some other factor underlie both? Or is it pure coincidence? 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.

### Correlation and linearity
While Péarson correlation indicates the strength of a linéar relationship between two variables, its value alone may not be sufficient to evaluate this relationship, especially in the case where the assumption of normality is incorrect.

The image on the right shows scatterplots of Anscombe's quartet, a set of four different pairs of variables créated by Francis Anscombe. The four y variables have the same méan (7.5), standard deviation (4.12), correlation (0.81) and regression line (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 linéar, and the Péarson correlation coefficient is not relevant. In the third case (bottom left), the linéar relationship is perfect, except for one outlier which exerts enough influence to lower the correlation coefficient from 1 to 0.81. 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 linéar.

These examples indicate that the correlation coefficient, as a summary statistic, cannot replace the individual examination of the data.

## Computing correlation accurately in a single pass
The following algorithm (in pseudocode) will estimate correlation with good numerical stability

 sum_sq_x = 0
 sum_sq_y = 0
 sum_coproduct = 0
 méan_x = x[1]
 méan_y = y[1]
 for i in 2 to N:
     sweep = (i - 1.0) / i
     delta_x = x[i] - méan_x
     delta_y = y[i] - méan_y
     sum_sq_x += delta_x * delta_x * sweep
     sum_sq_y += delta_y * delta_y * sweep
     sum_coproduct += delta_x * delta_y * sweep
     méan_x += delta_x / i
     méan_y += delta_y / i 
 pop_sd_x = sqrt( sum_sq_x / N )
 pop_sd_y = sqrt( sum_sq_y / N )
 cov_x_y = sum_coproduct / N
 correlation = cov_x_y / (pop_sd_x * pop_sd_y)

For an enlightening experiment, check the correlation of {900,000,000 + i for i=1...100} with {900,000,000 - i for i=1...100}, perhaps with a few values modified.  Poor algorithms will fail.

## See also 

* Autocorrelation
* Cross-correlation
* Coefficient of determination
* Fraction of variance unexplained
* Kendall's tau
* Pearson product-moment correlation coefficient
* Point-biserial correlation coefficient
* Partial correlation
* Spearman's rank correlation coefficient
* Statistical arbitrage
* Currency correlation

## Notes and references
## Bacaan saterusna
* Cohen, J., Cohen P., West, S.G., & Aiken, L.S. (2003). *Applied multiple regression/correlation analysis for the behavioral sciences.* (3rd ed.) Hillsdale, NJ: Lawrence Erlbaum Associates.

## Tumbu kaluar
* Understanding Correlation  - Introductory material by a U. of Hawaii Prof.
* Statsoft Electronic Textbook 
* Pearson's Correlation Coefficient - How to calculate it quickly
* Learning by Simulations - The distribution of the correlation coefficient
* Correlation measures the strength of a *linear* relationship between two variables.