# Is it possible for two random variables to be negatively correlated, but both be positively correlated with a third r.v.?

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?

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

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

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

$$(1−0.50.5−0.510.50.50.51)\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 ($$ρ=−0.5\rho=-0.5$$), the first and the third and the second and the third are positively correlated ($$ρ=0.5\rho=0.5$$).