My apologies if this has been asked earlier. I have been reading many textbooks and I am confused with the defination and meaning of covariance and correlation. I like to understand 1) The difference between covariance and correlation 2) How covariance and correlation are estimated 3) What is the difference between covariance , correlation, between subject and within subject variance ? using this toy dataset below.

    Id    Points    time
    1232  4.7       01.11.2010
    1232  5.4       03.21.2010
    5966  7.5       06.16.2000
    5966  7.35      11.28.2012
    5966  9.60      03.03.2014
    5010  8.60      08.31.2012
    5010  16.10     10.17.2016

Thanks in advance.


1 Answer 1


The toy dataset provided isn't very useful for explaining these concepts so I will try my best to explain in an easy-to-understand way.

The covariance of two variables is a measure of how much one variable goes up (or down) when the other goes up (or down). More technically, it is the average of the product of the differences of each variable from their expected values. It is calculated by first calculating the mean of each variable, then the difference between each measurement and the mean and multiplying the difference in one variable by that for the other variable. Then these are added up and the sum is divided by the number of observations.

$$ \text{Cov}(X,Y) = \frac{1}{n} \sum_{i=1}^{n}(x_i- \mu_X)(y_i- \mu_Y) $$

Strictly speaking this formula is valid when calculating the covariance in a population. If we are calculating the covariance from a sample then we divide by $n-1$ not $n$. This is because in a sample we have used up 1 degree of freedom when we used it to calculate the mean of the sample. This is a rather non technical explanation. I hope the rigour police are off-duty today, or if not then I hope they forgive me ! Obviously in a large sample the difference will be tiny. Side note: A long time ago I was once taught that if you are in a situation where the difference between dividing by $n-1$ or $n$ is important then you probably have much more important things to worry about.

Correlation is simply the covariance normalised by the variances of the two variables, so that it is bounded between -1 and +1.

$$ \text{Cor}(X,Y) = \frac{\text{Cov}(X,Y)}{\sigma_X \sigma_Y}$$

Within-subject variance is simply the variance of a set of measures within the same subject.

Between-subject variance doesn't really make sense. It could just be the covariance of measures between two subjects.

However I am guessing that your question comes from the analysis of experiments involving repeated measures where variables are often described as "within subject" or "between subject" which gives rise to the terms "within subject variation" and "between subject variation" - note it is "variation" and not "variance". A good example of a "within subject" variable is blood pressure - it varies within each person. A good example of a "between subject" variable is blood type - this is fixed within each person, but varies between subjects.

  • 1
    $\begingroup$ @RobertLong, thanks Robert, that is very easy to understand. Excellent explanation. $\endgroup$
    – Science11
    Jul 25, 2020 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.