Covariance and correlation
Part of a series on Statistics 
Correlation and covariance 

Correlation and covariance of random vectors 
Correlation and covariance of stochastic processes 
Correlation and covariance of deterministic signals

In probability theory and statistics, the mathematical concepts of covariance and correlation are very similar.^{[1]}^{[2]} Both describe the degree to which two random variables or sets of random variables tend to deviate from their expected values in similar ways.
If X and Y are two random variables, with means (expected values) μ_{X} and μ_{Y} and standard deviations σ_{X} and σ_{Y}, respectively, then their covariance and correlation are as follows:
covariance [math]\displaystyle{ \text{cov}_{XY} = \sigma_{XY} = E[(X\mu_X)\,(Y\mu_Y)] }[/math] correlation [math]\displaystyle{ \text{corr}_{XY} = \rho_{XY} = E[(X\mu_X)\,(Y\mu_Y)]/(\sigma_X \sigma_Y) }[/math],
so that
 [math]\displaystyle{ \rho_{XY} = \sigma_{XY} / (\sigma_X \sigma_Y) }[/math]
where E is the expected value operator. Notably, correlation is dimensionless while covariance is in units obtained by multiplying the units of the two variables.
If Y always takes on the same values as X, we have the covariance of a variable with itself (i.e. [math]\displaystyle{ \sigma_{XX} }[/math]), which is called the variance and is more commonly denoted as [math]\displaystyle{ \sigma_X^2, }[/math] the square of the standard deviation. The correlation of a variable with itself is always 1 (except in the degenerate case where the two variances are zero because X always takes on the same single value, in which case the correlation does not exist since its computation would involve division by 0). More generally, the correlation between two variables is 1 (or –1) if one of them always takes on a value that is given exactly by a linear function of the other with respectively a positive (or negative) slope.
Although the values of the theoretical covariances and correlations are linked in the above way, the probability distributions of sample estimates of these quantities are not linked in any simple way and they generally need to be treated separately.
Multiple random variables
With any number of random variables in excess of 1, the variables can be stacked into a random vector whose i^{ th} element is the i^{ th} random variable. Then the variances and covariances can be placed in a covariance matrix, in which the (i,j) element is the covariance between the i^{ th} random variable and the j^{ th} one. Likewise, the correlations can be placed in a correlation matrix.
Time series analysis
In the case of a time series which is stationary in the wide sense, both the means and variances are constant over time (E(X_{n+m}) = E(X_{n}) = μ_{X} and var(X_{n+m}) = var(X_{n}) and likewise for the variable Y). In this case the crosscovariance and crosscorrelation are functions of the time difference:
crosscovariance [math]\displaystyle{ \sigma_{XY}(m)=E[ (X_n\mu_X)\,(Y_{n+m}\mu_Y)], }[/math] crosscorrelation [math]\displaystyle{ \rho_{XY}(m) =E[ (X_n\mu_X)\,(Y_{n+m}\mu_Y)]/(\sigma_{X} \sigma_{Y}). }[/math]
If Y is the same variable as X, the above expressions are called the autocovariance and autocorrelation:
autocovariance [math]\displaystyle{ \sigma_{XX}(m)=E[ (X_n\mu_X)\,(X_{n+m}\mu_X)], }[/math] autocorrelation [math]\displaystyle{ \rho_{XX}(m) =E[ (X_n\mu_X)\,(X_{n+m}\mu_X)]/(\sigma_{X}^2). }[/math]
References
Original source: https://en.wikipedia.org/wiki/ Covariance and correlation.
Read more 