# Covariance and correlation

Main articles: Covariance and Correlation

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 μX and μY, and standard deviations σX and σY, respectively, then their covariance and correlation are as follows:

 covariance $\sigma_{XY} =E[ (X-E[X])\,(Y-E[Y])]$ correlation $\rho_{XY} =E[(X-E[X])(Y-E[Y])]/(\sigma_X \sigma_Y)$,

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. The covariance of a variable with itself (i.e. $\sigma_{XX}$) is called the variance and is more commonly denoted as $\sigma_X^2,$ 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, in which case the correlation does not exist).

## 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(Xn+m) = E(Xn) = μX and so on). In this case the covariance and correlation are functions of the time difference:

 cross-covariance $\sigma_{XY}(m)=E[ (X_n-\mu_X)\,(Y_{n+m}-\mu_Y)].$ cross-correlation $\rho_{XY}(m) =E[ (X_n-\mu_X)\,(Y_{n+m}-\mu_Y)]/(\sigma_{X} \sigma_{Y}),$

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. These distributions depend on the joint distribution of the pair of random quantities (X,Y) when the values are assumed independent across different pairs. In the case of a time series, the distributions depend on the joint distributions of the whole time-series.