Correlation – Can Two Random Variables Be Negatively Correlated but Both Be Positively Correlated with a Third?

correlation

Would it be possible for two variables to be negatively correlated with one another, yet be positively correlated with a third variable? Are there any concrete examples?

Best Answer

Certainly. Consider multivariate normally distributed data with a covariance matrix of the form

$$\begin{pmatrix} 1 & - & + \\ - & 1 & + \\ + & + & 1 \end{pmatrix}. $$

As an example, we can generate 1000 such observations with covariance matrix

$$\begin{pmatrix} 1 & -0.5 & 0.5 \\ -0.5 & 1 & 0.5 \\ 0.5 & 0.5 & 1 \end{pmatrix} $$

in R as follows:

library(mixtools)
set.seed(1)
xx <- rmvnorm(1e3,mu=rep(0,3),
    sigma=rbind(c(1,-.5,.5),c(-.5,1,.5),c(.5,.5,1)))
cor(xx[,c(1,2)])
cor(xx[,c(1,3)])
cor(xx[,c(2,3)])

The first two columns are negatively correlated ($\rho=-0.5$), the first and the third and the second and the third are positively correlated ($\rho=0.5$).

Related Question